A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Trouble using removeChildAt

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Posts
    24

    Trouble using removeChildAt

    I am using the following actionscipt to load a external swf file. I want to clear the content from the previous swf. I am trying to use removeChildAt() to accomplish this, but it is not working right.

    I have multiple layers and graphics in the slide and I do not have a good understanding of what a child is, I have managed to clear some of the content, but I can not clear all of it. I have created a massive loop trying to delete all the children, but some content still remains.

    Does anybody know why some content is not being removed, or is there a better method to clear a previous swf file? Thanks for your help,

    code:

    function home(evt:Event):void {
    var request:URLRequest = new URLRequest("shell.swf");
    var loader:Loader = new Loader();
    loader.load(request);
    addChild(loader);
    var i:Number = 0;
    do {
    removeChildAt(i);
    i++;
    }
    while(i <10);
    }


  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Why don't you just unload the movie? loader.unload();
    or removeChild(loader);
    Last edited by cancerinform; 06-19-2007 at 02:49 PM.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Jun 2007
    Posts
    24
    Well, that would make it easier I suppose.

    I am very new to Actionscript, so I am having trouble learning how to do different things in it. I took a class in C++ so I have a basic OOP framework of knowledge.

    This is what doesn't make sense to me. If I remove the loader I just loaded, I do not get anywhere. Its the previous slide that I want to delete. I am not smart enough...yet, in AS 3 to properly understand what I would need to do in order to unload a previous slide...I apologize for my ignorance.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Then use loader.unload(); You have to place it of course when you want to remove the slide.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Jun 2007
    Posts
    24
    Alls this ends up doing is unloading the slide I just loaded. I need to unload the previous slide. So if slide_1 loads slide_2 using the .unload() method. I need to unload slide 1. The first slide is not loaded with a loader, so I do not understand how to clear it.

    Im trying to wrap my head around this, but I am not having success.

    Slide_1 ones main file.
    At end of Slide_1 it loads a new url request, slide_2.

    Slide_2 Starts, but slide one is still in background.
    Using unload(loader), slide_2 is deleted.

    I am missing how to unload a slide that was not loaded with a loader. I should not have any problem unloading slide_2, since it was loaded with the loader, but slide_1 was not loaded with it and thus I can not seem to clear it

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I don't understand what your movie setup is. Are you using buttons or what to change the slide? When you load a slide into the same loader the new slide will replace the old one. Somewhere in your movie you create the loader instance. When you come to the slide part you don't use addChild any more, just loader.load().
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I guess the function is being run in the scope of Slide_1 and so it tries to remove elements inside this movie clip. To remove the whole clip try:

    parent.removeChild(this);

    However, if you remove the clip completely, loaded slide_2 wont show up either because you are adding them inside slide_1. You may need to add loaded clip to the parent timeline:

    parent.addChild(loader);

  8. #8
    Junior Member
    Join Date
    Jun 2007
    Posts
    24
    Ok... Basically, Slide 1 runs, it is text based like a pwoerpoint slide, at the end of slide one there is a proceed button. I want this button to load the next slide/.swf file (slide_2).

    The function is being run in the scope of slide_1 and that is where my problem was coming in.

    I am going to try to get a dummy swf at the beginning of the program he whole point of that swf would be to create a loader instance and load the real slide_1.

    Judging by your advice I believe this should solve my problem, we shall see... thanks for your help/patience

  9. #9
    Junior Member
    Join Date
    Jun 2007
    Posts
    24
    Ok, I think I may know the problem...because I am new to flash I have been using seperate actionscript for each new slide. This is causing me to redefine variables each time I load the new slide.

    I think that in order for me to incorporate what you have been trying to tell me, I need to create an external AS file and call that within each document...I think that has been my problem...

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