How to access the stage from an AS3 class in Adobe Flash?

A class in AS3 is not on the stage until you actually place it there. As a result, "this. Stage" will be null at compile time.

You can get around this problem by using the ADDED_TO_STAGE event to delay binding your listeners until the time is right public function MyClass(){ this. AddEventListener(Event. ADDED_TO_STAGE, addedToStageHandler); } private function addedToStageHandler(e:Event):void{ this.stage.

AddEventListener(KeyboardEvent. KEY_DOWN, dostuff); }.

A class in AS3 is not on the stage until you actually place it there. As a result, "this. Stage" will be null at compile time.

You can get around this problem by using the ADDED_TO_STAGE event to delay binding your listeners until the time is right. Public function MyClass(){ this. AddEventListener(Event.

ADDED_TO_STAGE, addedToStageHandler); } private function addedToStageHandler(e:Event):void{ this.stage. AddEventListener(KeyboardEvent. KEY_DOWN, dostuff); }.

Alrgiht! I've solved the stage problem. I still get a few errors though.

I'm getting the error that he can't find the keyboard and every error is located on the following kind of code "if (evt. KeyCode == Keyboard. RIGHT){ //stuff }" the error is the following: "1120: Access of undefined property Keyboard." already thanks for solving the stage thing!

Searched Google down for it but couldn't find anything relevant! – Graphithy Apr 22 '10 at 9:27 @Graphithy if you have a different question, ask a new question on stackoverflow instead of asking it in a comment. – davr Apr 22 '10 at 23:29.

1120: Access of undefined property Keyboard. There's your answer. You haven't defined the keyboard properties.

Which means you haven't imported to the package. Should look something like this: import flash.display. *; import flash.events.

*; import flash.ui. *; Advice: have a deeper look into importing. Try using flash builder, its much better for beginners and auto import classes so you don't need to memorize everything.

This answer has helped me a million times, but I don't yet have enough points to pop it up one, or I would. This happens generically when you try to access anything on the stage before it is added to stage. I was, for a while, using an init() in the constructor of all my projects main classes, but because of this issue, I no longer do.

Now, instead I have replaced it with this (where Main is the class constructor/name): public function Main():void { this. AddEventListener(Event. ADDED_TO_STAGE, init); super(); } ... private function init(e:Event):void { ... I hope this helps anyone else who read any of the books I did on flash, that offer the init() idea.And..thanks Greg W.

Actionscript 3 - How to access the stage from an AS3 class in Adobe Flash - Stack Overflow.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions