반응형
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="directionKey();" xmlns:ns1="comp1.*"> //프로그램이 완전히 출력 된 실행됨
<mx:Panel width="400" height="400" layout="absolute" horizontalCenter="0" verticalCenter="0" title="KeyboardEventTest">
<mx:Label text="charCode Test" horizontalCenter="-100" verticalCenter="-160" fontWeight="bold"/>
<mx:Label text="keyup" horizontalCenter="-120" verticalCenter="-130"/>
<mx:TextInput id="t1" keyUp="keyUp(event)" width="50" height="20" horizontalCenter="-60" verticalCenter="-130"/>
<mx:Label text="keydown" horizontalCenter="-120" verticalCenter="-103"/>
<mx:TextInput id="t2" keyDown="keyDown(event)" horizontalCenter="-60" verticalCenter="-100" width="50" height="20"/>
<mx:Label text="directionKey Test" fontWeight="bold" horizontalCenter="80" verticalCenter="-160"/>
<mx:Label text="x축" verticalCenter="-130" horizontalCenter="50"/>
<mx:Text id="xt" horizontalCenter="100" verticalCenter="-130" width="50" height="20"/>
<mx:Label text="y축" verticalCenter="-100" horizontalCenter="50"/>
<mx:Text id="yt" horizontalCenter="100" verticalCenter="-100" width="50" height="24"/>
<ns1:MyImage id="img" x="120" y="120">
</ns1:MyImage>
</mx:Panel>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function keyUp(event:KeyboardEvent):void{
t1.text = (String(event.charCode));
}
public function keyDown(event:KeyboardEvent):void{
t2.text = (String(event.charCode));
}
public function directionKey():void{
stage.addEventListener(KeyboardEvent.KEY_UP, test);
}
private var xx:int = 0;
private var yy:int = 0;
public function test(event:KeyboardEvent):void{
if(event.keyCode==Keyboard.UP){
img.y-=5;
yy-=5;
yt.text = ""+yy;
}
if(event.keyCode==Keyboard.DOWN){
img.y+=5;
yy+=5;
yt.text = ""+yy;
}
if(event.keyCode==Keyboard.LEFT){
img.x-=5;
xx-=5;
xt.text = ""+xx;
}
if(event.keyCode==Keyboard.RIGHT){
img.x+=5;
xx+=5;
xt.text = ""+xx;
}
if(event.ctrlKey){
if(event.keyCode==Keyboard.UP){
img.y-=50;
yy-=50;
yt.text = ""+yy;
}
if(event.keyCode==Keyboard.DOWN){
img.y+=50;
yy+=50;
yt.text = ""+yy;
}
if(event.keyCode==Keyboard.LEFT){
img.x-=50;
xx-=50;
xt.text = ""+xx;
}
if(event.keyCode==Keyboard.RIGHT){
img.x+=50;
xx+=50;
xt.text = ""+xx;
}
}
}
]]>
</mx:Script>
</mx:Application>
반응형