A subreddit for all questions related to programming in any language.
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; } }
}