as3.0编程:键盘的操作


键盘的点击与弹起:
Source:        
stage.addEventListener(KeyboardEvent.KEY_DOWN, xKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, xKeyUp);
function xKeyDown(event:KeyboardEvent):void{
        kb.text = "点击"+event.keyCode;
};
function xKeyUp(event:KeyboardEvent):void{
        kb.text = "弹起"+event.keyCode;
};
按键状态的确认:
Source:        
var space_flag:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN,xKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP,xKeyUp);
stage.addEventListener(Event.ENTER_FRAME,xEnterFrame);
function xKeyDown(evt:KeyboardEvent):void{
    if(evt.keyCode == Keyboard.SPACE){
        space_flag = true;
    }
}
function xKeyUp(evt:KeyboardEvent):void{
    if(evt.keyCode == Keyboard.SPACE){
        space_flag = false;
    }
}
function xEnterFrame(evt:Event):void{
    if(space_flag){
                mc.gotoAndStop(2);
        }else{
                mc.gotoAndStop(1);
    }
}                        
键盘的KeyCode表示:
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/1942.html

你可能感兴趣的:(html,编程,Flash,UP)