`

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

分享到:
评论

相关推荐

    flex自定义“折叠手风琴”组件CollapsibleAccordion

    几经尝试发现是由于Flex控件在旋转后中文就不显示了,因此做了相应修改以支持中文,并添加了一些删除,增加子组件的方法,以方便编程式的使用。当然如果熟悉了Flex组件的生命周期,可以根据需求增添功能。 对于中文...

    设置TabNavigator组件的标签头的自定义皮肤

    设置TabNavigator组件的标签头的自定义皮肤,可以设置样式等等,内容较少,只是提供一种自定义皮肤设置的思路

    FLEX从入门到精通.pdf

     5.3 FlexBuilder3中的新内容  5.3.1 新向导  5.3.2 设训,模式的增强  5.3.3 开发功能的增强  5.3.4 CS3套件的整合  5.4 本章小结 第Ⅱ部分 使用FIex3开发应用程序  第6章 使用FIexBuilder3  6.1 ...

    vue实现自定义H5视频播放器的方法步骤

    前段时间基于vue写了一个自定义的video播放器组件,踩了一些小坑, 这里做一下复盘分享出来,避免日后重复踩坑… 设计阶段 这里就直接放几张完成后的播放状态图吧,界面布局基本就是flex+vw适配一把梭,也比较容易. ...

    flex3的cookbook书籍完整版dpf(包含目录)

    自定义组件样式属性 9.9节.同一个程序中使用多个主题 9.10节.编译主题SWC 9.11节.应用嵌入字体 9.12节.从SWF文件中嵌入字体 9.13 节. 嵌入图像的皮肤 9.14节.从SWF文件中嵌入皮肤 9.15节.编程实现组件应用皮肤 9.16 ...

    react-tree:React的分层对象树组件

    针对长对象标签进行了优化:标签对于容器而言太大时省略号 针对深层嵌套结构进行了优化:当嵌套项可能隐藏在容器外部时,容器将变为可滚动 空指示器:如果未提供数据,则向用户显示一条消息 加载指示器:提供is...

    vue实现简单瀑布流布局

    vue中的瀑布流布局组件 需求:图片容器宽度固定,高度根据图片自适应,图片一行不能排列时候,换行依次从左往右排列。(瀑布流概念) 另外结合vue-lazy实现懒加载 ( npm i vue-lazyload –save-dev) 使用也很简单...

    react-native-demo:使用react-native版本写的APP组件演示,同时对源代码添加注释(由于开发用mac,故暂未兼容安卓)

    React本机本项目综合了如下react-native组件导航器路由WebView网页TabBarIOS导航切换栏TouchableHighlight点按动作查看布局文字文字react-native-swiper图片浏览自定义组件本项目综合了如下react-native的API 动画...

    Maven权威指南 很精典的学习教程,比ANT更好用

    本例中所用的技术 7.2. simple-parent项目 7.3. simple-model模块 7.4. simple-weather模块 7.5. simple-persist模块 7.6. simple-webapp模块 7.7. 运行这个Web应用 7.8. simple-command模块 7.9. 运行这...

    react-login:风格ReactNative培训

    风格ReactNative培训课程目标知道如何在基本组件中使用内联样式了解StyleSheet中的样式定义知道如何使用尺寸获取屏幕尺寸结合基本组件标签以创建应用程序界面练习内容创建一个CodeGym登录页面,如下所示包括CodeGym...

    StyleReactNativeTraining

    结合基本组件标签以创建应用程序界面 练习内容 创建一个CodeGym登录页面,如下所示 包括CodeGym的徽标,用户名,密码,忘记密码,按钮登录... 参考界面为照片 教程 使用ImageBackground标签为您的应用创建背景 使用...

    软件界面设计工具_3款合集

    通过现有元素或其它自定义控件创建自定义控制组件。 在其它设计中创建将要使用的控件设计。 以常用的文件格式添加图标与图片。 从能够显示您将获得什么的控件面板中进行拖放操作。 属性编辑程序使您能将每个元素...

    Crystal Reports 2008 水晶报表官方中文傻瓜教程(翻译).pdf

    利用 Flash、Flex 和 Xcelsius 实现的高级信息可视化...32 改善的最终用户报表查看体验..........................33 增强的报表设计器功能................................33 新增的灵活部署选项....................

Global site tag (gtag.js) - Google Analytics