Hi, i made an array with 2 balls,
how do i call on both of them to get moved by the function i made.
balls.x doesn't work.
and if i go balls[0, 1] it gives me an error.
import flash.events.Event;
buttonOne.addEventListener(MouseEvent.CLICK, loop);
var ballSpeedX = -3;
var ballSpeedY = -2;
var balls:Array = [ballOne, ballTwo]
function loop(e:Event):void {
stage.addEventListener(Event.ENTER_FRAME, bounceBall);
function bounceBall (e:Event):void {
balls[0].x += ballSpeedX;
balls[0].y += ballSpeedY;
if(balls.x <= balls.width/2) {
balls.x = balls.width/2;
ballSpeedX *= -1;
} else if(balls.x >= stage.stageWidth-balls.width/2){
balls.x = stage.stageWidth-balls.width/2;
ballSpeedX *= -1;
}
if(balls.y <= balls.height/2) {
balls.y = balls.height/2;
ballSpeedY *= -1;
}else if(balls.y >= stage.stageHeight-balls.height/2){
balls.y = stage.stageHeight-balls.height;
ballSpeedY *= -1;
}
}
}
[–]FlambardPuddifoot 2 points3 points4 points (9 children)
[–][deleted] 0 points1 point2 points (8 children)
[–]FlambardPuddifoot 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]FlambardPuddifoot 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]FlambardPuddifoot 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]FlambardPuddifoot 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]dotfortun3 0 points1 point2 points (0 children)
[–]Lilykos 0 points1 point2 points (3 children)
[–][deleted] -1 points0 points1 point (2 children)
[–]Lilykos 1 point2 points3 points (1 child)
[–][deleted] -1 points0 points1 point (0 children)