grebs
December 3rd, 2008, 10:49 AM
I am trying to add acceleration to a movieclip called Ground. I have written this code
package {
import flash.display.Stage;
import flash.display.Sprite;
import flash.ui.*;
import flash.events.*;
public class Ground extends Sprite{
private var xVel:Number = 0;
private var xAcc:Number = -0.25;
public function Accelerate()
{
init();
}
private function init():void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, go);
}
private function go(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.UP){
xVel += xAcc;
}
}
}
}
The movieclip loads fine and i get no errors, but when the up button is pressed nothing happens. Can anyone help?
package {
import flash.display.Stage;
import flash.display.Sprite;
import flash.ui.*;
import flash.events.*;
public class Ground extends Sprite{
private var xVel:Number = 0;
private var xAcc:Number = -0.25;
public function Accelerate()
{
init();
}
private function init():void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, go);
}
private function go(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.UP){
xVel += xAcc;
}
}
}
}
The movieclip loads fine and i get no errors, but when the up button is pressed nothing happens. Can anyone help?