Posted By

Winkyboy on 05/28/10


Tagged

events listener timing as3


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

MacEvelly
IsoJon
tspitzr


Create your own custom events in AS3


 / Published in: ActionScript 3
 

URL: http://theflashconnection.com/content/creating-and-dispatching-your-own-custom-events-as3

A very easy way to have child movieclips cause events in their parent code to occur.

  1. stage.addEventListener(MouseEvent.CLICK, stageClicked);
  2.  
  3. function stageClicked(event:MouseEvent):void {
  4. stage.removeEventListener(MouseEvent.CLICK, stageClicked);
  5. clip1.play();
  6. }
  7.  
  8. clip1.addEventListener("done", clip1Done);
  9.  
  10. function clip1Done(event:Event):void {
  11. clip2.play();
  12. }
  13.  
  14. clip2.addEventListener("done", clip2Done);
  15.  
  16. function clip2Done(event:Event):void {
  17. clip1.gotoAndStop(1);
  18. clip2.gotoAndStop(1);
  19. stage.addEventListener(MouseEvent.CLICK, stageClicked);
  20. }
  21.  
  22.  
  23. // at the end of the timeline of a child movieclip (such as in this example of "clip1" or "clip2" you add this:
  24. stop();
  25. dispatchEvent(new Event("done"));

Report this snippet  

You need to login to post a comment.