你插入元标签到你的MXML和AS文件是个Flex编译器提供信息用的.
元标签不会被编译进可执行的代码中,但是元标签提供的信息控制了编译器怎样编译代码..(官方资料,好像更准确,更权威点,水平有限...太麻烦了....需要的朋友自己去下好了...)
元标签在<fx:Metadata>和<fx:Script>的区别:
元标签在<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.