Need info on how to solve a function

26 Views Asked by At

What am i doing wrong? The program is meant to move a picture of a plane over the screen. The speed of the plane is increasing over time. The stage has a timer that runs the function 10 times per second

private function myTimer(e) {
    var speed:int = 0;
    plane.x = plane.x + speed
    speed = speed + 10
}
1

There are 1 best solutions below

0
Simon Groenewolt On

You are defining the speed variable inside the function, this causes it to be initialized to 0 on every call, and since you only add to the speed after changing the x of the plane it never moves.

If you move the var speed:int = 0; definition outside of the function the changes will not be overwritten on each call.