AS3: onAdded Event Listener


/ Published in: ActionScript 3
Save to your folder(s)

The point of this listener is to detect when something has been added to the stage. Purely experimental.


Copy this code and paste it in your HTML
  1. function onAdded(e:Event):void {
  2. // get reference to child from event object
  3. // as child variable of target will not yet be defined
  4. var childRef:MovieClip = e.target as MovieClip;
  5. trace(childRef.type + " " + stage.numChildren);
  6.  
  7. // check the name of the reference for correct instance name
  8. if (childRef && childRef.name == "child"){
  9. e.target.removeEventListener(Event.ADDED, onAdded);
  10. }
  11. }
  12. //stage.addEventListener(Event.ADDED, onAdded);

Report this snippet


Comments


You need to login to view comments.