Pomeranje loptice tastaturom
/**
* Copyright stamenkovski87 ( http://wonderfl.net/user/stamenkovski87 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6c6P
*/
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class FlashTest extends Sprite {
private var lopta:Sprite;
public function FlashTest() {
init();}
private function init():void{
lopta = new Sprite();
stage.addChild(lopta);
lopta.graphics.beginFill(0xff0000);
lopta.graphics.drawCircle(0,0,40);
lopta.x = stage.stageWidth/2;
lopta.y = stage.stageHeight/2;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKBEvent);
}
private function onKBEvent (event:KeyboardEvent):void{
switch(event.keyCode){
case Keyboard.UP:
lopta.y -=10;
break;
case Keyboard.DOWN:
lopta.y +=10;
break;
case Keyboard.LEFT:
lopta.x -=10;
break;
case Keyboard.RIGHT:
lopta.x +=10;
break;
default:
break;
}
}
}
}