I create multiple MC's with the following code:
function addCharacter() {
var newCharacter:characterBob = new characterBob();
this.addChild(newCharacter);
newCharacter.x=1000 - (50*counter);
newCh开发者_Go百科aracter.y=50;
counter = counter + 1
}
Now i'd like to remove a bunch of them from the stage. Is there a way i can do this in AS3?
Thanks in advance for any advice.
You can try something like:
for each (var o:DisplayObject in this) {
if (o is characterBob) {
removeChild(o);
}
}
Perhaps a better option would be to put each "characterBob" created into an array. Then loop through the array and remove each object.
var bobs:Array = new Array();
function addCharacter() {
var newCharacter:characterBob = new characterBob();
this.addChild(newCharacter);
newCharacter.x=1000 - (50*counter);
newCharacter.y=50;
counter = counter + 1;
bobs.push(newCharacter);
}
function removeAllBobs():void {
while (bobs.length > 0) {
removeChild(bobs.shift());
}
}
while(myDisplayObjectContainer.numChildren > 0){
myDisplayObjectContainer.removeChildAt(0);
}
That will remove all children of the specified DisplayObjectContainer (Sprite or Movieclip)
精彩评论