当前位置: 首页 > news >正文

flex metadata tag学习

Flex引入了元数据标签的概念,它告诉编译器如何编译这段Flex 或actionscript代码。大多数人都使用过[Bindable]标签,元数据标签是一种 特殊的标签,它在代码中的作用就是向编译器提供如何编译程序的信息。实际上,这些标签并没有被编译到生成的SWF文件中,而只是 告诉编译器如何生成SWF 文件。 这篇Post结合网上相关的 资料 以及Adobe的 help resource center的相关材料 介绍了16个元数据标签。

[ArrayElementType]

实际上,定义一个数组通常来说是一件很平常的事情,因为数组中的元素可以是任何类型的。不过,使用ArrayElementType元数据标签可以让你定义数组元素的数据类型。下面的例子展示了如何使用[ArrayElementType]:

[ArrayElementType(”String”)]
public var arrayOfStrings:Array;

[ArrayElementType(”Number”)]
public var arrayOfNumbers:Array;

[ArrayElementType(”mx.core.UIComponent”)]
public var arrayOfUIComponents:Array;

[Bindable]

Bindable元数据标签是最经常用到的一个元数据标签,因为它使程序组件之间的数据同步变得很容易。Bindable可以用来绑定简单数据类型、类、复杂数据类型以及函数。绑定数据的时候,你必须先使用元数据标签定义一下数据。Bindable也可以用来绑定到事件。

[DefaultProperty]

DefaultProperty元数据标签用来将一个单一属性设定为某个类的默认属性。它允许在一个容器标签内设定属性,而不用定义属性的名字。一个简单的例子就是一个自定义Button类。 Listing 3 展示了一个简单的Button类,它将label属性设定为了DefaultProperty。 Listing 4 展示了label属性是如何在自定义Button标签中作为一个字符串定义的。

[Deprecated]

A class or class elements marked as deprecated is one which is considered obsolete, and whose use is discouraged in the current release. While the class or class element still works, its use can generate compiler warnings.

[Embed]

Embed元数据标签用来导入图片到程序。可以通过两种方式使用Embed。你可以将图片嵌入到ActionScript中并将其指派给一个变量(如同下面代码中的第一个例子),或者你也可以将图片直接指派给组件的属性(使用下面代码中的第二个例子所示的语法规则)。

例1:

[Embed(source=”myIcon.gif”)]
[Bindable]
public var myIcon:Class;<mx:Button label=”Icon Button 1″ icon=”{myIcon}”/>
<mx:Button label=”Icon Button 2″ icon=”{myIcon}”/>

例2:

<mx:Button label=”Icon Button 1″ icon=”@Embed(source=myIcon.gif’)”/><mx:Button label=”Icon Button 2″ icon=”@Embed(source=myIcon.gif’)”/>

上面这两个例子产生的结果是一样的。创建myIcon类的好处是,它在一个类中只定义一次并可以绑定到程序中的多个组件。

[Event]

Event元数据标签用来声明那些被自定义类分派的事件。将这个元数据标签添加到类定义中之后,你就可以在MXML标签中添加事件处理函数来初始化该自定义类。

[Effect]

Effect元数据标签用来定义一个自定义效果,当某个事件发生的时候该效果会被分派。

[IconFile]

IconFile 是用来定义一个jpg,gif或者png文件的文件名的,它在你的自定义类中作为图标来使用。[Embed]元数据标签可以用来嵌入图片、SWF文件、音 乐文件以及视频文件等,而IconFile则只是用来嵌入用来作为自定义类图标的文件。下面是一个IconFile的例子:

[IconFile(”icon.png”)]
public class CustomButton extends Button
{}

[Inspectable]

在使用Flex Builder 2的时候,你可能会希望某些自定义组件的属性在代码提示和属性检查器(property inspector)中显示,Inspectable元数据标签就是用来定义那些属性的。

[InstanceType]

当在一个模板对象中声明一个像IDeferredInstance这样的变量时,InstanceType元数据标签就用来声明对象的类型。下面是InstanceType的用法:

[InstanceType(”package.className”)]

[NonCommittingChangeEvent]

NonCommittingChangeEvent元数据标签在某个特定事件发生的时候可以防止变量在事件发生的过程中被更改。

[RemoteClass]

RemoteClass 可以用来将一个ActionScript类绑定到一个Java类或一个ColdFusion CFC。这样做可以自动转换数据类型。下面的例子将包com.mydomain中的名为MyClass的ActionScript类绑定到了同一个包中名 为MyClass的Java类:

package com.mydomain {
[Bindable]
[RemoteClass(alias=”com.mydomain.MyClass”)]
public class MyClass {
public var id:int; public var myText:String;

}
}

[Style]

Style元数据标签用来为组件定义自定义样式属性的。只需要简单地将Sytle元数据标签添加到类的定义当然,然后就可以使用getSytle方法获取它的值了。

标签 描述
[ArrayElementType] 在数组中定义所有允许的数据类型。
[Bindable] 声明一个属性可以在代码中使用数据绑定表达式。
[DefaultProperty] 定义组件在MXML中使用时的默认属性的名称。
[Deprecated] 标识一个类或类的元素是不推荐使用的,这样编译器能认出他并在被调用时给出一个警告信息。
[Effect] 定义MXML的特效属性名称。
[Embed] 在编译时导入 JPED,PNG,SVG 或 SWF文件。也会导入SWC文件的图片资源。他的功能等同于MXML中的 @Embe 语法。
[Event] 定义MXML的事件属性的名称和类型。
[Exclude] 使 Flex Builder 的标签检查器忽略类元素。语法类似 [Exclude(name=”label”, kind=”property”)]
[ExcludeClass] 是 Flex Builder 标签检查器忽略类。这相当于ASDoc中的 @private 标签。
[IconFile] 定义一个图标文件,使组件在Adobe Flex Builder的插入面板中以该图标显示。
[Inspectable] 定义一个属性的列表,供组件使用者在 Flex Builder 的的属性提示和标签检查中使用。同时也定义了属性的可用值。
[InstanceType] 指定了 IDeferredInstance 中的,属性接受的数据类型。
[NonCommittingChangeEvent] 定义一个事件过渡触发器。
[RemoteClass] 把一个ActionScript对象映射到Java对象。
[Style] 为组件的样式属性定义一个MXML标签属性。
[Transient] 当一个 ActionScript 对象被映射到Java对象后,被该标签标识的属性,会从发送到服务端的数据中忽略掉。

 

thanks :    http://www.geoinformatics.cn/?p=899

 

 

English help document:

 

About metadata tags

Metadata tags provide information to the Flex compiler that describes how your components are used in a Flex 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
flex代码
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 Flex compiler, you can reference it in MXML, as the following example shows:
flex代码

 

 

If you omit the [Event] metadata tag from your class definition, Flex issues a syntax error when it compiles your MXML file. The error message indicates that Flex does not recognize the enableChanged property.

The Flex compiler recognizes component metadata statements in your ActionScript class files and MXML files. The metadata tags define component attributes, data binding properties, events, and other properties of the component. Flex interprets these statements during compilation; they are never interpreted during run time. 

Metadata statements are associated with a class declaration, an individual data field, or a method. They are bound to the next line in the file. When you define a component property or method, add the metadata tag on the line before the property or method declaration. 

Metadata tags in ActionScript

In an ActionScript file, when you define component events or other aspects of a component that affect more than a single property, you add the metadata tag outside the class definition so that the metadata is bound to the entire class, as the following example shows: 

 

flex代码:

 

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 the default value of the property for Adobe® Flex™ Builder™. For more information on using this tag, see Inspectable metadata tag.

Metatdata tags in MXML

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:
flex代码
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代码

相关文章:

  • 201521123108 《Java程序设计》第2周学习总结
  • flex子组件关闭父组件
  • Eclipse安装svn插件问题解决
  • 利用chmod获取权限
  • tomcat一闪而过解决方法
  • APP加固
  • jforum开源论坛安装
  • Vue.js之组件(component)
  • jforum架构和主要配置文件的说明
  • Axure--一个很好的原型设计软件
  • flex程序初始化顺序
  • [C/C++] C/C++中数字与字符串之间的转换
  • flex datagrid 设置超链接
  • 攻克vue路由
  • 如何设置光驱启动
  • 【407天】跃迁之路——程序员高效学习方法论探索系列(实验阶段164-2018.03.19)...
  • CentOS 7 防火墙操作
  • HTTP 简介
  • Java深入 - 深入理解Java集合
  • Python_OOP
  • 记一次删除Git记录中的大文件的过程
  • 使用 QuickBI 搭建酷炫可视化分析
  • 手机端车牌号码键盘的vue组件
  • 我是如何设计 Upload 上传组件的
  • 一个普通的 5 年iOS开发者的自我总结,以及5年开发经历和感想!
  • 原生 js 实现移动端 Touch 滑动反弹
  • 正则表达式小结
  • 3月7日云栖精选夜读 | RSA 2019安全大会:企业资产管理成行业新风向标,云上安全占绝对优势 ...
  • Hibernate主键生成策略及选择
  • 阿里云重庆大学大数据训练营落地分享
  • 京东物流联手山西图灵打造智能供应链,让阅读更有趣 ...
  • 蚂蚁金服CTO程立:真正的技术革命才刚刚开始
  • ​queue --- 一个同步的队列类​
  • ###项目技术发展史
  • (C#)if (this == null)?你在逗我,this 怎么可能为 null!用 IL 编译和反编译看穿一切
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (附源码)ssm基于web技术的医务志愿者管理系统 毕业设计 100910
  • (简单) HDU 2612 Find a way,BFS。
  • (篇九)MySQL常用内置函数
  • (企业 / 公司项目)前端使用pingyin-pro将汉字转成拼音
  • (强烈推荐)移动端音视频从零到上手(下)
  • (一)spring cloud微服务分布式云架构 - Spring Cloud简介
  • (译)计算距离、方位和更多经纬度之间的点
  • (转)linux下的时间函数使用
  • .bat批处理(五):遍历指定目录下资源文件并更新
  • .gitignore文件_Git:.gitignore
  • .Net 4.0并行库实用性演练
  • .NET MVC之AOP
  • .NET中使用Redis (二)
  • [acwing周赛复盘] 第 69 场周赛20220917
  • [BT]BUUCTF刷题第8天(3.26)
  • [BZOJ 3531][Sdoi2014]旅行(树链剖分+线段树)
  • [C++]高精度 bign (重载运算符版本)
  • [CISCN 2023 初赛]go_session
  • [codeforces] 25E Test || hash