Wednesday, 3 December 2008

Event metadata tag in Flex

This article gives an explanation of how metadata can be used in Flex:

Use the [Event] metadata tag to define the MXML property for an event and the data type of the event object that a component emits. You insert the [Event] metadata tag before the class definition in an ActionScript file, or in the block in an MXML file.

For more information on defining custom events, see Creating Custom Events.

The [Event] metadata tag has the following syntax:

[Event(name="eventName", type="package.eventType")]

The following table describes the properties of the [Event] metadata tag:

eventName: Specifies the name of the event, including its package name.
eventType: Specifies the class that defines the data type of the event object. The class name is either the base event class, Event, or a subclass of the Event class

The following example identifies the myClickEvent event as an event that the component can dispatch:

[Event(name="myClickEvent", type="flash.events.Event")]

If you do not identify an event in the class file with the [Event] metadata tag, the MXML compiler generates an error if you try to use the event name in MXML. Any component can register an event listener for the event in ActionScript by using the addEventListener() method, even if you omit the [Event] metadata tag.

The following example identifies the myClickEvent event as an event that an ActionScript component can dispatch:

[Event(name="myEnableEvent", type="flash.events.Event")]
public class MyComponent extends UIComponent
{
...
}

The following example shows the [Event] metadata tag in the tag in an MXML file:






[Event(name="myEnableEvent", type="flash.events.Event")]


....


No comments: