If you want your component to broadcast events other than the events it may inherit from a parent class, you must call the dispatchEvent() method in the component's class file.
The dispatchEvent() method is defined in the mx.events.EventDispatcher class and is inherited by all components that extend UIObject. (See EventDispatcher class.)
You should also add an Event metadata tag at the top of the class file for each new event. For more information, see About the Event tag.
Note: For information about handling component events in a Flash application, see Handling Component Events.
In the body of your component's ActionScript class file, you broadcast events using the dispatchEvent() method. The dispatchEvent() method has the following syntax:
dispatchEvent(eventObj)
The eventObj parameter is an ActionScript object that describes the event (see the example later in this section).
You must declare the dispatchEvent function in your code before you call it, as follows:
private var dispatchEvent:Function;
You must also create an event object to pass to dispatchEvent(). The event object contains information about the event that the listener can use to handler the event.
You can explicitly build an event object before dispatching the event, as the following example shows:
var eventObj = new Object(); eventObj.type = "myEvent"; eventObj.target = this; dispatchEvent(eventObj);
You can also use a shortcut syntax that sets the value of the type property and the target property and dispatches the event in a single line:
ancestorSlide.dispatchEvent({type:"revealChild", target:this});
In the preceding example, setting the target property is optional, because it is implicit.
The description of each event in the Flash MX 2004 documentation lists the event properties that are optional and required. For example, the ScrollBar.scroll event takes a detail property in addition to the type and target properties. For more information, see the event descriptions in Components Dictionary.
The following table lists the common events that are broadcast by various classes. Every component should broadcast these events if they make sense for that component. This is not a complete list of events for all components, just ones that are likely to be reused by other components. Even though some events specify no parameters, all events have an implicit parameter: a reference to the object broadcasting the event.
| Event | Use |
|---|---|
|
|
Used by the Button component, or whenever a mouse click has no other meaning. |
|
|
Used by List, ComboBox, and other text-entry components. |
|
|
Used by ScrollBar and other controls that cause scrolling (scroll "bumpers" on a scrolling pop-up menu). |
In addition, because of inheritance from the base classes, all components broadcast the following events:
| UIComponent event | Description |
|---|---|
|
|
The component is creating or loading its subobjects. |
|
|
The component is unloading its subobjects. |
|
|
The component now has the input focus. Some HTML-equivalent components (ListBox, ComboBox, Button, Text) might also broadcast |
|
|
The component has lost the input focus. |
|
|
The component has been moved to a new location. |
|
|
The component has been resized. |
The following table describes common key events:
| Key events | Description |
|---|---|
|
|
A key is pressed. The |
|
|
A key is released. |
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00003105.html
Comments
murk379 said on Oct 10, 2004 at 8:51 PM : larsendaniel said on Oct 31, 2004 at 12:02 AM : No screen name said on Dec 18, 2004 at 7:21 PM : Fallfish said on Jan 13, 2005 at 1:50 AM : No screen name said on Jun 2, 2005 at 5:54 AM :