Flex4中自定义组件的元标签

 

Adobe 写道
Metadata tags in custom components

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>的区别:

 

Adobe 写道
A key difference between the <fx:Metadata> and <fx:Script> tags is that text within the <fx:Metadata> tag is
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.

 

下载:http://help.adobe.com/en_US/flex/using/flex_4.5_help.pdf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值