User Guide

48 Using Metadata Tags in Custom Components
In this example, you add the [Event] metadata tag before the class definition to indicate that
the class dispatches an event named
enableChanged. You also include the [Inspectable]
metadata tag to indicate that the
enableTA property is accessible in Flex Builder.
In an MXML file, you insert the metadata tags either in an
<mx:Script> block along with
your ActionScript code, or in an
<mx:Metadata> block, as the following example shows:
<?xml version="1.0"?>
<!-- TextAreaEnabled.mxml -->
<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Metadata>
[Event(name="enableChange", type="flash.events.Event")]
</mx:Metadata>
<mx:Script>
<![CDATA[
// Import Event class.
import flash.events.Event;
// Define class properties and methods.
private var _enableTA:Boolean;
// Add the [Inspectable] metadata tag before the individual property.
[Inspectable(defaultValue="false")]
public function set enableTA(val:Boolean):void {
_enableTA = val;
this.enabled = val;
// Define event object, initialize it, then dispatch it.
var eventObj:Event = new Event("enableChange");
dispatchEvent(eventObj);
}
]]>
</mx:Script>
</mx:TextArea>
A key difference between the <mx:Metadata> and <mx:Script> tags is that text within the
<mx:Metadata> tag is inserted before the generated class declaration, but text within
<mx:Script> tag is inserted in the body of the generated class declaration. Therefore,
metadata tags like
[Event] and [Effect] must go in an <mx:Metadata> tag, but the
[Bindable] and [Embed] metadata tags must go in an <mx:Script> tag.