Reputation: 17
Okay, after learning tutorials online, I'm trying to make a bouncing ball in AS3.
Here's my code thus far:
var count:Number = 0;
var bounceHeight:Number = 100;
var floorHeight:Number = 300;
var speed:Number = .1;
function run(e:Event):void
{
ball_mc.y = floorHeight - Math.abs(Math.cos(count)) * bounceHeight;
count += speed;
}
{
this.addEventListener(Event.ENTER_FRAME(run));
}
Thanks in advance for the help!
EDIT: The compiler errors are
Scene 1, Layer 'Layer 1', Frame 1, Line 13 1195: Attempted access of inaccessible method ENTER_FRAME through a reference with static type Class.
Scene 1, Layer 'Layer 1', Frame 1, Line 13 1136: Incorrect number of arguments. Expected 2.
Upvotes: 0
Views: 2273
Reputation: 15955
Within your closure, addEventListener
requires a type parameter and a listener function.
Your type is Event.ENTER_FRAME
and your handler is run
, which means to call run
every frame you need:
addEventListener(Event.ENTER_FRAME, run);
Therefore, your code should be:
function run(e:Event):void
{
ball_mc.y = floorHeight - Math.abs(Math.cos(count)) * bounceHeight;
count += speed;
}
this.addEventListener(Event.ENTER_FRAME, run);
Upvotes: 1