Question
removeChild problem
Hi,
I have the following code to add some objects (Ball) in stage and to remove them...
var Balls:Array = new Array();
BtnA.addEventListener(MouseEvent.CLICK, AddBox);
function AddBox(ev) {
for (var i:uint = 0; i<3; i++) {
var Ball:MyBall = new MyBall();
Balls.push(Ball);
addChild(Ball)
Ball.name = "A"+i;
Ball.x = 100 +i*50
Ball.y = 100
}
}
BtnB.addEventListener(MouseEvent.CLICK, RemoveBox);
function RemoveBox(ev){
for (var i:uint = 0; i<3; i++) {
removeChild(Balls )
}
}
The first time I click the button A I add 3 balls in stage and with click in button B remove them...
The second time I click the button A and add 3 balls in stage again but with click in button B I can't remove them...
The error is " ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at demoArray_fla::MainTimeline/RemoveBox() "
Where I'm wrong?
I have the following code to add some objects (Ball) in stage and to remove them...
var Balls:Array = new Array();
BtnA.addEventListener(MouseEvent.CLICK, AddBox);
function AddBox(ev) {
for (var i:uint = 0; i<3; i++) {
var Ball:MyBall = new MyBall();
Balls.push(Ball);
addChild(Ball)
Ball.name = "A"+i;
Ball.x = 100 +i*50
Ball.y = 100
}
}
BtnB.addEventListener(MouseEvent.CLICK, RemoveBox);
function RemoveBox(ev){
for (var i:uint = 0; i<3; i++) {
removeChild(Balls )
}
}
The first time I click the button A I add 3 balls in stage and with click in button B remove them...
The second time I click the button A and add 3 balls in stage again but with click in button B I can't remove them...
The error is " ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at demoArray_fla::MainTimeline/RemoveBox() "
Where I'm wrong?