zoukankan      html  css  js  c++  java
  • 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];
            }
  • 相关阅读:
    链表操作 —— 61_链表旋转
    链表操作 —— 25_k个一组翻转链表
    链表操作 —— 19_删除链表倒数第N个结点
    链表操作 —— 1. 2_两数相加
    Hash相关 —— 2. 387_字符串中的第一个唯一字符
    Hash相关 —— 1. 1_两数之和
    Maven02-Maven 仓库、生命周期、插件、镜像
    mvn test 运行测试不显示测试统计信息和测试结果
    Maven 概述
    Spring源码03---parseDefaultElement
  • 原文地址:https://www.cnblogs.com/xcai/p/2380465.html
Copyright © 2011-2022 走看看