/ Published in: ActionScript
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
package
{
import flash.display.MovieClip;
/**
* ...
* @author Jeff Nehlsen
*/
public class CustomEventExample extends MovieClip
{
public function CustomEventExample()
{
// Add an event handler for both types of events in my CustomEvent class
addEventListener(CustomEvent.EVENT_DEFAULT, onDefaultEvent);
addEventListener(CustomEvent.EVENT_CUSTOM, onCustomEvent);
// Dispatch the 'default' event
dispatchEvent(new CustomEvent());
// Dispatch a 'custom' event.
dispatchEvent(new CustomEvent(CustomEvent.EVENT_CUSTOM));
}
// When a custom event is caught, a message will show.
private function onCustomEvent(e:CustomEvent):void
{
trace("Custom event caught!");
}
// When a default evnet is caught, this message will show.
private function onDefaultEvent(e:CustomEvent):void
{
trace("Default event caught!");
}
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                