Saturday, September 10, 2011

Flex :: Metadata tag - Event

The [Event] metadata tag is used to define the MXML property for an event and the data type of the event object that a component dispatches.

Following is the syntax for [Event] metadata tag

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

name property of metadata tag specifies the name of the event only.
type property of metadata tag specifies the class that defines the event including entire package.

The [Event] metadata tag is inserted before class defination in an Action Script file or in <mx:Metadata> block ina n MXML file.

If the event is not identify using type and name property defined in [Event] metadata tag then MXML compiler generates an error.

Following is an example:

ActionScript Class

[Event(name="custom_event", type="myPackage.events")]
public class MyClass extends UIComponent
{
   ...
}

MXML Document

<?xml version="1.0"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Metadata>
        [Event(name="custom_event", type="myPackage.events")]
    </mx:Metadata>

    ....
 
</mx:Canvas>

No comments:

Post a Comment