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.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...