Posted By

visualadvance on 02/08/10


Tagged

as3 stage ADDEDTOSTAGE


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

adrianparr
davidino1978
tspitzr
mitien


AS3: Check for Stage


 / Published in: ActionScript 3
 

Use this to test if the stage exists before you execute a function (usually some sort of init). This is useful if you have items that need to be drawn onto the stage (displayObjects) before something else happens.

  1. // stick this code in the constructor of your class
  2. if (stage)
  3. {
  4. init ();
  5. } else
  6. {
  7. addEventListener (Event.ADDED_TO_STAGE, init);
  8. }
  9.  
  10. // then use this code for an init function
  11. private function init (evt:Event = null):void
  12. {
  13. // something
  14. }

Report this snippet  

You need to login to post a comment.