zoukankan      html  css  js  c++  java
  • flex 里键盘事件

    一、

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
          addedToStage="stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown)"   
         click="clickEvt(event)"
         layout="absolute"
         frameRate="6"
         creationComplete="start()" keyFocusChange="testKey(event)"    
      backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#990000, #FF9900]">
     <mx:Script source="SnakeMain.as"/> 

    二、<?xml version="1.0" encoding="utf-8"?>  
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
                    layout="absolute" 
                    applicationComplete="appComplete();">  
        <mx:Script>  
           <![CDATA[  
               import mx.controls.Alert;  
                import flash.events.KeyboardEvent;  
                  
                //监听keyboard事件  
                private function appComplete():void  
                {  
                     this.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
                    //this.addEventListener(KeyboardEvent.KEY_UP, myKeyUp);  
                    //this.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);  
                }  
                   private function keyHandler(event:KeyboardEvent):void
                   {
                   trace(event.charCode);
                   }
                //响应keyup事件  
                private function myKeyUp(evt:KeyboardEvent):void  
                {  
                    mx.controls.Alert.show('evt.keyCode=' + evt.keyCode.toString()+"\n"+ "弹起\n", "KeyUp");  
                }  
                  
                //响应keydown事件  
                private function myKeyDown(evt:KeyboardEvent):void  
                {  
                    t1.text=t1.text + 'evt.charCode=' + evt.charCode + ' evt.keyCode=' + evt.keyCode + ' evt.keyLocation=' + evt.keyLocation + " 按下\n";  
                }  
            ]]>  
        </mx:Script>  
        <mx:TextArea x="261" 
                     y="226" 
                     id="t1" 
                     width="381" 
                     height="200"/>  
        <mx:TextInput x="372" 
                      y="114" 
                      id="t2"/>  
    </mx:Application> 
    当你把所有方法写在一个as文件里时用第一种方法获取键盘事件

    当在mxml页面里获取键盘事件时用第二种方法!!!!!

     不管怎么去处理,都要找准给谁添加键盘监听事件 ok 这样就哦了!!

  • 相关阅读:
    利用JNI技术在Android中调用、调试C++代码
    iOS在线更新framework,使用NSBundle动态读取
    CocoaPods pod install
    Quartz 2D在ios中的使用简述二:创建画布
    iOS并发编程笔记【转】
    openCV C++ 代码笔记
    Quartz 2D在ios中的使用简述一:坐标体系
    ios视频播放器,代码和界面分离
    mac显示和隐藏文件
    3点画圆
  • 原文地址:https://www.cnblogs.com/nianshi/p/1774200.html
Copyright © 2011-2022 走看看