PDA

View Full Version : game key movement


reece973
01-03-2009, 10:24 AM
hi ive recently got cs4 and befor i had flash 8 so i dont now how to use as3 yet butt i cold use as 2 perfectly the problem is i dont no how to make a mc move on key press for eg it would be Key.down(key.right on action script 2 but im stuck any answers all help appriciated:)

theclincher
01-04-2009, 07:47 AM
Use event listeners. This is an example from Moock's Essential Actionscript 3.0, which I highly recommend anyone wanting to learn AS3 to read.


package {
import flash.display.*;
import flash.events.*;
public class GlobalKeyboardSensor extends Sprite {
public function GlobalKeyboardSensor ( ) {
// Register to be notified whenever a key is pressed
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
}
// This function is invoked whenever a key is pressed while
// Flash Player has system focus
private function keyDownListener (e:KeyboardEvent):void {
trace("A key was pressed.");
}
}
}


Just replace the debug output with something like movieHandle.x += 10 or with whatever you are trying to do.