キーボードの確認。
♥0 |
Line 45 |
Modified 2009-07-23 13:50:52 |
MIT License
archived:2017-03-20 02:43:22
ActionScript3 source code
/**
* Copyright pykgg476 ( http://wonderfl.net/user/pykgg476 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/mHRO
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class keySample extends Sprite
{
private var ball:Sprite;
public function keySample()
{
init();
}
private function init():void{
ball = new Sprite();
ball.graphics.beginFill(0xff0000);
ball.graphics.drawCircle(0,0,40);
ball.graphics.endFill();
ball.x = stage.stageWidth/2;
ball.y = stage.stageHeight/2;
addChild(ball);
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyboardEvent);
}
public 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;
addEventListener(Event.ENTER_FRAME,onEnterFrame);
break;
default:
break;
}
}
public function onEnterFrame(event:Event):void{
ball.x++;
}
}