You insert metadata tags into your MXML and ActionScript files to provide information to the Adobe® Flex® compiler.
Metadata tags do not get compiled into executable code, but provide information to control how portions of your code
get compiled.
For more information about additional metadata tags that you use when creating an application, such as
the [Embed]metadata tag, see “Embedding assets” on page 1693.
About metadata tags
Metadata tags provide information to the compiler that describes how your components are used in an application.
For example, you might create a component that defines a new event. To make that event known to the Flex compiler
so that you can reference it in MXML, you insert the [Event] metadata tag into your component, as the following
ActionScript class definition shows:
[Event(name="enableChanged", type="flash.events.Event")]
class ModalText extends TextArea {
...
}
In this example, the [Event] metadata tag specifies the event name and the class that defines the type of the event
object dispatched by the event. After you identify the event to the compiler, you can reference it in MXML, as the
following example shows:
你插入元标签到你的MXML和AS文件是个Flex编译器提供信息用的.
元标签不会被编译进可执行的代码中,但是元标签提供的信息控制了编译器怎样编译代码..(官方资料,好像更准确,更权威点,水平有限...太麻烦了....需要的朋友自己去下好了...)
元标签在<fx:Metadata>和<fx:Script>的区别:
inserted before the generated class declaration, but text within <fx:Script> tag is inserted in the body of the
generated class declaration. Therefore, metadata tags like [Event] and [Effect] must go in an <fx:Metadata> tag,
but the [Bindable] and [Embed] metadata tags must go in an <fx:Script> tag.
元标签在<fx:Metadata> and <fx:Script>的关键区别在于:<fx:Metadata> 编译后插入到类申明前,而<fx:Script>内的元标签将会插入到类体里,所以,元标签[Event]和[Effect]最好放到<fx:Metadata>里,但是[Bindable][Embed]最好在<fx:Script>内..
Flex中元标签的说明:
[SkinPart]
Define a property of a component that corresponds to a skin part. For more
information, see “SkinPart metadata tag” on page 2384.
[SkinState]
Defines the view states that a component’s skin must support. For more
information, see “SkinState metadata tag” on page 2385.
[HostComponent]
Specifies the host component for a Spark skin class. For more information, see
“HostComponent metadata tag” on page 2380
[Effect]
Defines the MXML property name for the effect. For more information, see
“Effect metadata tag” on page 2379.
===============================================================================
HostComponent metadata tag
Use the [HostComponent] metadata tag to identify the host component of a Spark skin class. The [HostComponent]
metadata tag has the following syntax:
<Metadata>
[HostComponent(componentName)]
</Metadata>
For example:
<Metadata>
[HostComponent("spark.components.Button")]
</Metadata>
As a result of this metadata, Flex creates the property hostComponent on the skin class. You can then use this property
to access public members of the host component’s instance from within the skin. For example, in a Button skin, you
can access the Button’s style properties.
SkinPart metadata tag
Components can uses skins made up of skin parts. Use the [SkinPart] metadata tag to define a property of a
component that corresponds to a skin part. Users of the component do not set the skin part properties directly. The
component's skin sets the skin part properties.
Insert the [SkinPart] metadata tag before any property that corresponds to a skin part. The [SkinPart] metadata
tag has the following syntax:
[SkinPart(type="package.className", required="true_false")]
/**
* Optional ASDoc comment.
*/
Property definition
The type and required attributes are optional. The type attribute specifies the data type of the skin part, which
determines whether the part is static or dynamic. The default value of type is determined by the data type of the
property.
The required attribute specifies if the skin class must define the skin part. The default value of the required attribute
is false.
SkinPart metadata is inherited by subclasses of the component.
For more information, see “Spark Skinning” on page 1597.
Static skin parts
Static skin parts are created once by an instance of a component, and are defined as shown below: 2385 USING FLEX 4.5
Custom components
[SkinPart]
/**
* ASDoc comment for thumb.
*/
public var thumb:spark.components.Button;
The data type for static parts is the data type of the part property. In this example above, the type is Button. Therefore,
static skin parts typically omit the type attribute of the [SkinPart] metadata tag.
Dynamic skin parts
Some components create multiple instances of a skin part. For example, the Spark ButtonBar control can create any
number of buttons. Dynamic skin parts can be created multiple times by a component. The data type of a dynamic skin
part property is always IFactory, but the metadata tag can optionally define the data type of the skin part by using the
type property.
For example from the spark.components.ButtonBar class:
[SkinPart(required="false", type="mx.core.IVisualElement")]
/**
* A skin part that defines the first button.
*/
public var firstButton:IFactory;
Because the data type of the skin part is IFactory, it is a dynamic skin part. Each instance of the skin part is of type
mx.core.IVisualElement.
SkinState metadata tag
The [SkinState] metadata tag defines the view states that a component’s skin must support. The tag goes outside the
component’s class definition, and inside the package definition. The tag is inherited, but can be overridden in a
subclass.
The SkinState tag has the following ActionScript syntax:
[SkinState("stateName")]
The following example defines two skin states for a component:
package spark.components.supportCl asses
{
/**
* Optional ASDoc comment. */
[SkinState("n ormal")]
/**
* Optional ASDoc comment. */
[SkinState("disabled")]
public class MyClass {}
For more information, see “Spark Skinning” on page 1597.