Konami Code for Flex 3

I never did add an easter egg to any of my applications, but recently I stumbled upon konamicodesites.com, a site that lists other sites that use the konami code.

I’ve been working mostly with flex applications so I created a simple component to add 30 life to my apps, this component dispatches an event when the user inputs the Konami Code on their keyboard.

To use the component just add it anywhere in your application.

<konamicode:KonamiCodeCatch success="Alert.show('+30 lives!!!')" />

here is the code of the component:

?View Code ACTIONSCRIPT
<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
	<mx:Metadata>
		[Event(name="success", type="flash.events.Event")]
	</mx:Metadata>
	<mx:Script>
		<![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 = "";
			    }
 
			}
		]]>
	</mx:Script>
 
</mx:UIComponent>

thanks to everyone who posted on stack overflow

Popularity: 100% [?]

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Konami Code for Flex 3”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>