Skip to content

Instantly share code, notes, and snippets.

@illuzor
Created December 16, 2013 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/7988116 to your computer and use it in GitHub Desktop.
Save illuzor/7988116 to your computer and use it in GitHub Desktop.
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