code_junkie

Check component initilaze before add events in actionscript 3

Nov 14th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. if (_myComponent != null)
  2. {
  3. // add listeners
  4. }
  5.  
  6. if (mcWithComponents.stage) doStuff();
  7. mcWithComponents.addEventListener(Event.ADDED_TO_STAGE, doStuff);
  8.  
  9. private function doStuff(e:Event = null):void
  10. {
  11. mcWithComponents.myButton.addEventListener(MouseEvent.CLICK, buttonClicked);
  12. }
  13.  
  14. public function mcWithComponents() // constructor
  15. {
  16. if (stage) init();
  17. addEventListener(Event.ADDED_TO_STAGE, init);
  18. }
  19. private function init(e:Event = null):void
  20. {
  21. myButton.addEventListener(MouseEvent.CLICK, buttonClicked);
  22. }
Add Comment
Please, Sign In to add comment