Note that there are some explanatory texts on larger screens.

plurals
  1. POkonami code in flex
    primarykey
    data
    text
    <p>What would be the best way to implement the konami code into a flex application?</p> <p>I want to create a component to add it on all my proyects, just for fun.</p> <p>thanks</p> <p>UPDATE: I made a simple component, thanks to ZaBlanc</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:UIComponent xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"&gt; &lt;mx:Metadata&gt; [Event(name="success", type="flash.events.Event")] &lt;/mx:Metadata&gt; &lt;mx:Script&gt; &lt;![CDATA[ // up-up-down-down-left-right-left-right-B-A public static const KONAMI_CODE:String = "UUDDLRLRBA"; // signature private var signatureKeySequence:String = ""; private function init():void{ systemManager.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); } private function onKeyDown(event:KeyboardEvent):void{ var keyCode:int = event.keyCode; switch (keyCode) { case Keyboard.UP: signatureKeySequence += "U"; break; case Keyboard.DOWN: signatureKeySequence += "D"; break; case Keyboard.LEFT: signatureKeySequence += "L"; break; case Keyboard.RIGHT: signatureKeySequence += "R"; break; case 66: //Keyboard.B only for AIR :/ signatureKeySequence += "B"; break; case 65: //Keyboard.A only for AIR too :( signatureKeySequence += "A"; break; default: signatureKeySequence = ""; break; } // crop sequence signatureKeySequence = signatureKeySequence.substr(0, KONAMI_CODE.length); // check for konami code if (signatureKeySequence == KONAMI_CODE) { dispatchEvent(new Event("success")); signatureKeySequence = ""; } } ]]&gt; &lt;/mx:Script&gt; &lt;/mx:UIComponent&gt; </code></pre> <p>to test it</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:konamicode="konamicode.*"&gt; &lt;mx:Script&gt; &lt;![CDATA[ import mx.controls.Alert; ]]&gt; &lt;/mx:Script&gt; &lt;konamicode:KonamiCodeCatch success="Alert.show('+30 lives!!!')" /&gt; &lt;/mx:Application&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload