A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] Im sure this is an easy AS3 101 Output error, but how to fix it?

  1. #1
    Member
    Join Date
    Mar 2003
    Posts
    50

    resolved [RESOLVED] Im sure this is an easy AS3 101 Output error, but how to fix it?

    I'm trying to learn AS3 and have a test AS3 file to try and learn how to load/unload external swf files into a container on CLICK of 3 different buttons I have. What does this Output error mean and how would I fix it? I don't understand what it means that it has to be a "child of the caller."

    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:isplayObjectContainer/removeChild()
    at test01_loadEXT_swf_fla::MainTimeline/goToHome()

    Here's the AS3 that I have:

    Code:
    var page_loader:Loader = new Loader();
    
    contact_mc.addEventListener(MouseEvent.CLICK, Contact);
    function Contact(Event:MouseEvent):void {
    	var request:URLRequest = new URLRequest("contact.swf");
    	page_loader.load(request);
    	addChild(page_loader);
    	removeChild(container_mc);
    }
    
    bio_mc.addEventListener(MouseEvent.CLICK, Bio);
    function Bio(Event:MouseEvent):void {
    	var request:URLRequest = new URLRequest("bio.swf");
    	page_loader.load(request);
    	addChild(page_loader);
    	removeChild(container_mc);
    }
    
    home_mc.addEventListener(MouseEvent.CLICK, Home);
    function Home(Event:MouseEvent):void {
    	var request:URLRequest = new URLRequest("home.swf");
    	page_loader.load(request);
    	addChild(page_loader);
    	removeChild(container_mc);
    }

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    It means you are trying to remove something from something other than its parent. In this case, it looks like you are trying to remove container_mc after you have already removed it. Since it is no longer a child of the parent (the root, here) after removal, the second removal call fails.

  3. #3
    Member
    Join Date
    Mar 2003
    Posts
    50
    Okay, that I can understand. Thanks for translating it into "english."

    So on all buttons I removed the last line of code:

    removeChild(container_mc);

    I had on the stage my container_mc with an instance name of "container_mc" so I deleted that too. Everything now works without errors. Thanks.

    Another question about this though...

    So is each .swf that I am loading into the container actually being unloaded/removed when I click on another button? Visually it appears as such, but I thought I actually had to tell it in the AS to "remove" the .swf from the container or it would still be "there?" I don't see anywhere in the code where I am actually telling it to remove everything in the "container_mc" and only load the .swf that I've told it to when clicking on each button.


    Thanks...
    Man, I really need to get the Flash CS3 for Dummies book.....

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Since you are loading all your content into the same loader, it automatically replaces previous content. A Loader can only have one child at a time. You could explicitly call page_loader.unload() if you wanted to remove that loaded content without loading up other content.

    You also do not need to add your page_loader more than once. It does no harm to do so, though.

  5. #5
    Member
    Join Date
    Mar 2003
    Posts
    50
    Quote Originally Posted by 5TonsOfFlax View Post
    Since you are loading all your content into the same loader, it automatically replaces previous content. A Loader can only have one child at a time. You could explicitly call page_loader.unload() if you wanted to remove that loaded content without loading up other content.

    You also do not need to add your page_loader more than once. It does no harm to do so, though.
    I just had an "ahhhhhhhh" moment after reading what you said. That explains so much with some of the tutorials I have been looking at.

    In all of the beginner tutorials I've looked at I have not seen anyone actually say that a loader can only have one child at a time and that it automatically unloads the previous content. It may seem like common knowledge, but for someone learning like me it makes it confusing when it's not been explained.

    Thanks for taking the time to explaining everything to me. I really appreciate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center