A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: MovieClip instances and removeChildAt

  1. #1
    Senior Member
    Join Date
    Feb 2000
    Posts
    226

    MovieClip instances and removeChildAt

    The code below creates new instances of 2 MovieClips, seems all fine.

    Code:
    var myOnStageClip:MovieClip = this.text_mc;
    var myLinkage:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip)));
    var myDuplicateClip:MovieClip = new myLinkage();
    myDuplicateClip.name = "TextElement" + "_Dup"+i;
    MovieClip(root).container.addChild(myDuplicateClip);
    	
    var myOnStageClip1:MovieClip = this.drag_mc;
    var myLinkage1:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip1)));
    var myDuplicateClip1:MovieClip = new myLinkage1();
    myDuplicateClip1.name = "TextController" + "_Dup1";
    myDuplicateClip1.drag_mc = myDuplicateClip;
    MovieClip(root).container.addChild(myDuplicateClip1);
    I have some code that should delete these new instances. It works well for the first created MovieClip. The second MovieClip is not removed.

    Code:
    trace("childs: "+MovieClip(root).container.numChildren);
    for(var i:int = 0; i < MovieClip(root).container.numChildren; i++){
           var child:DisplayObject = MovieClip(root).container.getChildAt(i);
           trace(child.name);
    }
    In my example the first trace outputs 9, which is correct. But then there are only 6 outputs in the for statement! 3 are missing which are probably exactly the references to the MovieClip instances in the second part of the first code attachment whci8h are not deleted.

    I have no clue what is going on here, apparantly they are childs of the container mc as they are included in the numChildren output but they are not returned in the for statement, neither do I get error messages. Anyone has an idea what is going on here?

    Thanks,
    Raoul

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You say that you've got code which should delete the instances. Is the code you posted (with just a trace) actually the code you're running, or do you have a removeChild in there too? If you are doing removeChild, then the number of children will change as you go, and each time you remove a child the following children will move up an index, meaning you'll skip one for each one removed.

  3. #3
    Senior Member
    Join Date
    Feb 2000
    Posts
    226
    hmmm, that probably is the reason, I will check that, thanks!

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