Hi, again me with another problem… Idea is to create 2 buttons bt1 and bt2, and ball mc exported as Ball class. When you click bt1 it creates balls array and position all balls on stage according to math.random(). When you click bt2 balls start to fall down.
Problem:this can be created only 1 time after exporting swf. I try removeChild() when ball.y hit some position and balls.splice() but there is a Error #1009: and Error #2025:… I’ve been looking for a reason for this error on numerous web pages but i can’t figure out how to solve it…
There is a .fla file in attach. CS4 and AS3
Thanks for advice!!!
Code:
var balls:Array=new Array();
var numBalls:Number=10;
bt1.addEventListener(MouseEvent.CLICK,OnClickB1);
function OnClickB1(e:MouseEvent):void {
for (var i:uint; i<numBalls; i++) {
var ball:Ball = new Ball();
addChild(ball);
balls.push(ball);
ball.x=Math.random()*stage.stageWidth;
ball.y=Math.random()*stage.stageHeight;
}
}
bt2.addEventListener(MouseEvent.CLICK,OnClickB2);
function OnClickB2(ev:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, OnEnterFrame);
}
function OnEnterFrame(evt:Event):void {
for (var i:uint; i<numBalls; i++) {
var ball:Ball=balls*;
ball.y+=5;
if (ball.y>300) {
balls.splice(0,numBalls);
removeChild(ball);
removeEventListener(Event.ENTER_FRAME, OnEnterFrame);
}
}
}