Key.isDown... [FMX]

Hi all,

I am trying to use th following code to animte an object across the screen:

if (Key.isDown(Key.LEFT)) {

	speed++;
	clip._x -= speed/5;
	trace(speed);
}

speed is a variable with a set number.
the effect is a sort of acceleration.

The problem I have is: How do I reset the speed after when the Key is not down?

try this:
if (Key.isDown(Key.LEFT)) {

speed++;
clip._x -= speed/5;
trace(speed);
} else {
speed = 0
}

That should reset the speed!

Hey thanks… it helped a bit but there was a conflict with the movie clip’s (enterFrame) call back of the function which constantly set the speed to 0.

I found another trick by creating a way to reset what other keys were setting the speed to:

if (Key.isDown(Key.RIGHT)) {
if (leftSpeed > 0){
trace (“reset speed”);
speed = 0;
leftSpeed = 0;
}
speed++;
clip._x += speed/5;
rightSpeed = clip._x;
trace(speed);
if (speed>=40) {
speed = 40;
}
}

this works really well.
Now i have to find something that does a kind a deceleration when the Key is released…