package { import flash.display.Sprite; import flash.events.KeyboardEvent; import flash.ui.Keyboard; public class KeyCodes extends Sprite { private var ball:Sprite; public function KeyCodes() { init(); } private function init():void { ball = new Sprite(); addChild(ball); ball.graphics.beginFill(0x000000); ball.graphics.drawCircle(0, 0, 40); ball.graphics.endFill(); ball.x = stage.stageWidth / 2; ball.y = stage.stageHeight / 2; stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyboardEvent ); } private function onKeyboardEvent(event:KeyboardEvent):void { switch(event.keyCode ) { case Keyboard.UP : ball.y -= 10; break; case Keyboard.DOWN : ball.y += 10; break; case Keyboard.LEFT : ball.x -= 10; break; case Keyboard.RIGHT : ball.x += 10; break; default: break; } } } }
키보드 방향키를 이용한 무비클립위치 이동시키기
'AS3 > ActionScript' 카테고리의 다른 글
Array 함수를 이용해서 무비클립 복제와 Drag시키기 (0) | 2009.04.20 |
---|---|
removeChild, removeEventListener를 통한 메모리상 객체지우기 (0) | 2009.04.20 |
사인/코사인을 이용한 원그리기 (8) | 2009.03.15 |
두점 사이 거리값 구하기 (0) | 2009.03.14 |
lineTo와 moveTo를 활용한 그림판 만들기 (0) | 2009.02.18 |