Reputation: 21
I'm developing a game.I've attached random movieClips from library. I've movieClips named picLeft1
, picLeft2
, picLeft3
and so on in library. Its working fine but i'm having problem removing it. the code below is for the attachment of movieclip. Here ranque
is an array which stores randomly generated numbers up to 5 and HolderL
is the movieClip in which I want to attach the movieClip. And q
is a sprite.
for (var i:int = 0; int<3; i++) {
que_mc.push("picLeft"+ranque[i]);
var que_mc_class:Class = getDefinitionByName(que_mc[i]) as Class;
q = new que_mc_class();
this["HolderL"+(i+1)].addChild(q);
}
my code for removing the movieclip is given below.I want to remove all the movieclip attached in HolderL
. but this code is not working.
for(var j:int = 1; j<=3; j++) {
this["HolderL"+j].removeChild(q);
}
Upvotes: 0
Views: 330
Reputation: 22604
Flash Player 11 allows you to use this:
for (var j:int = 1; j<=3; j++) {
var container : DisplayObjectContainer = this["HolderL"+j];
container.removeChildren();
}
Earlier versions don't have the removeChildren()
command; you have to have two loops: One to loop to iterate over the container movie clips, one to traverse the display list and remove all children.
Shortest way to remove all children of a container prior to FlashPlayer 11:
while (container.numChildren > 0) container.removeChildAt(0);
Upvotes: 2
Reputation: 90863
It's not clear from your code what q
is, but basically if you want to remove all the children from one movie clip, the simplest is to loop through all the children and remove them one by one. For example:
for (var i:int = container.numChildren - 1; i >= 0; i--) {
container.removeChildAt(i);
}
Upvotes: 1