• Array应用,对象应用


    private var desction:Array = [0,0,0,0];
            private function onKeyDownHandler(_evt:KeyboardEvent):void {
                switch (_evt.keyCode) {
                    case 37:
                        desction[0] = 1;
                        break;
                    case 38:
                        desction[1] = 1;
                        break;
                    case 39:
                        desction[2] = 1;
                        break;
                    case 40:
                        desction[3] = 1;
                        break;
                    default:
                        break;
                }
                //txt.text = desction.toString();
                trace("值:" + desction.toString())
                downTest(desction.join(""));
            }
            private function downTest(k:String):void {
                switch (k) {
                        case "0110":
                            txt.text = "  上+右";
                            break;
                        case "1100":
                            txt.text = "  上+左";
                            break;
                        case "0011":
                            txt.text = "  下+右";
                            break;
                        case "1001":
                            txt.text = "  下+左";
                            break;
                        case "1010":
                            txt.text = "  左+右";
                            break;
                        case "0101":
                            txt.text = "  上+下";
                            break;
                        case "1000":
                            txt.text = "  左";
                            break;
                        case "0100":
                            txt.text = "  上";
                            break;
                        case "0010":
                            txt.text = "  右";
                            break;
                        case "0001":
                            txt.text = "  下";
                            break;
                        default:
                            break;
                    }
            }
            private function onKeyUpHandler(_evt:KeyboardEvent):void {
                switch (_evt.keyCode) {
                    case 37:
                        desction[0] = 0;
                        break;
                    case 38:
                        desction[1] = 0;
                        break;
                    case 39:
                        desction[2] = 0;
                        break;
                    case 40:
                        desction[3] = 0;
                        break;
                    default:
                        break;
                }
            }

     对象应用:

    var key_obj:Object = new Object();

    private function onKeyDownHandler1(_evt:KeyboardEvent):void {
                var _code:String = String.fromCharCode(_evt.charCode);
                key_obj[_code] = true;
                
                for (var p:String in key_obj){ //用于其它字母和数字鍵
                    trace("当前按下的键有:" + p + "值=true(key_obj[p])");
                }
                /*_evt.ctrlKey && trace("Ctrl键被按下");
                   _evt.altKey && trace("Alt键被按下");
                 _evt.shiftKey && trace("Shift键被按下");
    */
            }

            private function onKeyUpHandler1(_evt:KeyboardEvent):void {
                var _code:String = String.fromCharCode(_evt.charCode);
                
                key_obj[_code] = null;
                delete key_obj[_code];
            }
  • 相关阅读:
    JavaScript 事件对象Event的工具类
    高度组件专一性的松耦合系统CI的MVC
    [转]解决PHP相对目录问题最有效的办法
    CodeIgniter 用户登录注册模块
    记录js的四种函数写法
    Firebug 控制台API
    jQuery实战(一)
    apache:一个ip绑定多个域名的问题(续)
    JavaScript 字符串操作(一)
    hdu 1166 敌兵布阵【树状数组入门】
  • 原文地址:https://www.cnblogs.com/xcai/p/2380465.html
Copyright © 2020-2023  润新知