I have two buttons, one that adds a ball to an array and displays it and one pops a ball from the array and removes it from the display list, the add button works fine, however when i push the subtract button I get this message **ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
**Here is my code, thanks:
var iconArray:Array = new Array();
var ball:Ball;
var icon_count:int = 0;
add_btn.addEventListener(MouseEvent.CLICK,startAdd);
sub_btn.addEventListener(MouseEvent.CLICK,stopAdd);
function startAdd(evt:MouseEvent){
addBall(1);
}
function stopAdd(evt:MouseEvent){
subBall(1);
}
function subBall(num_ball:int){
add_btn.removeEventListener(MouseEvent.CLICK,startAdd);
for(var i:int = 0; i < num_ball; i++){
iconArray.pop()
removeChild(ball);
trace(iconArray);
}
}
function addBall(num_ball:int){
for(var i:int = 0; i < num_ball; i++){
ball = new Ball();
iconArray.push(ball);
trace(iconArray);
addChild(ball);
ball.x = icon_count * 100;
ball.y = 100;
icon_count++;
}
}