konami code in flex

前端 未结 3 952
-上瘾入骨i
-上瘾入骨i 2021-02-01 14:51

What would be the best way to implement the konami code into a flex application?

I want to create a component to add it on all my proyects, just for fun.

thanks<

3条回答
  •  礼貌的吻别
    2021-02-01 15:44

    var unlockCode:Array = new Array(38,38,40,40,37,39,37,39,66,65,13);
    
    var keyPressArray:Array = new Array();
    stage.addEventListener(KeyboardEvent.KEY_DOWN, checkUnlockCode);
    
    function checkUnlockCode(e:KeyboardEvent):void {
        if (keyPressArray.length >= unlockCode.length) {
            keyPressArray.splice(0,1);
            keyPressArray.push(e.keyCode.toString());
        } else {
            keyPressArray.push(e.keyCode.toString());
        }
        trace(keyPressArray);
        if (keyPressArray.toString() == unlockCode.toString()) {
            trace(unlockCode);
        }
    }
    

提交回复
热议问题