当前位置:软件学习 > Flash >>

as 3.0使用键盘代码

as 3.0使用键盘代码

package cn.com.webstudio{
        import flash.display.Sprite;
        import flash.events.KeyboardEvent;
        import flash.ui.Keyboard;

        public class KeyCodes extends Sprite {
                private var box:Sprite;

                public function KeyCodes() {
                        init();
                }
                private function init():void {
                        box=new Sprite();
                        addChild(box);
                        box.graphics.beginFill(0xff0000);
                        box.graphics.drawRect(0,0,40,40);
                        box.graphics.endFill();
                        box.x=stage.stageWidth / 2;
                        box.y=stage.stageHeight / 2;
                        stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyboardEvent);

                }
                public function onKeyboardEvent(event:KeyboardEvent):void {
                        switch (event.keyCode) {
                                 case Keyboard.DELETE:
                                        removeChild (box)
                                                               
                        }
                }
        }
}

补充:flash教程,As3.0 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,