Return to Snippet

Revision: 40803
at February 8, 2011 06:54 by jeffnehlsen


Initial Code
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!");
		}
	}

}

Initial URL

                                

Initial Description

                                

Initial Title
AS3 Custom Event Dispatching

Initial Tags

                                

Initial Language
ActionScript