PDA

View Full Version : Help with a for() loop



fs_tigre
July 31st, 2008, 09:24 AM
Hi,
I need some help please. What I want to do is to throw the Sprite (ball) five times, using the for () loop.
What am I missing here? Do I need a timer? If yes, how would I use it?

var yVel = -10;
var xVel = 5;
var yAcc = 1;

var ball:Sprite = new Srprite();
for(var i =0; i < 5; i++)
{
ball.graphics.beginFill(Math.random()* 0x000000, 1);
ball.graphics.drawCircle(0,0,10);
ball.graphics.endFill();
ball.y = 250;
ball.x = 250;
addChild(ball);
addEventListener(Event.ENTER_FRAME, throwBall);
}

function throwBall(evt:Event):void
{
ball.x += xVel;
ball.y += yVel;

yVel += yAcc;

}

Thanks,
fs_tigre

Magik5
July 31st, 2008, 09:32 AM
var yVel = -10;
var xVel = 5;
var yAcc = 1;


for(var i:int =0; i < 5; i++)
{
var ball:Sprite = new Sprite();
ball.graphics.beginFill(Math.random()* 0x000000, 1);
ball.graphics.drawCircle(0,0,10);
ball.graphics.endFill();
/*ball.y = 250;
ball.x = 250;*/
ball.y = Math.random()*stage.stageHeight;
ball.x = Math.random()*stage.stageWidth;
addChild(ball);
addEventListener(Event.ENTER_FRAME, goBall);
}

function goBall(e:Event):void
{
e.target.x += xVel;
e.target.y += yVel;

yVel += yAcc;

}


=]

fs_tigre
July 31st, 2008, 09:48 AM
Wow, Thank you very much.

Felixz
July 31st, 2008, 01:01 PM
var ball:Shape = new Shape();You can use Shape to gain less resources consumption, but MouseEvent will be unavaiable.