Created
December 16, 2013 14:46
-
-
Save illuzor/7988116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var myText:TextField; // move the var to class-level | |
// if you create var inside function it not be visible in another function | |
private function init(e:Event = null):void { | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
trace('stage has been found') | |
stage.addEventListener(KeyboardEvent.KEY_DOWN, EnterStart); | |
myText = new TextField(); | |
myText.text = "Republic of Code"; | |
addChild(myText); | |
} | |
private function EnterStart(e:KeyboardEvent):void { | |
stage.removeEventListener(KeyboardEvent.KEY_DOWN, EnterStart); | |
trace('enter has been pressed') | |
//var myText:TextField; // equals null | |
//remove this var from here | |
if (e.keyCode == 13) { | |
gameStart(); | |
removeChild(myText); | |
} else { | |
init(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment