flex 常用元标签讲解

阅读更多

Flex 引入了元数据标签的概念,大多数人都使用过的 [Bindable] 标签便是其中的 meta tag 之一,它在代码中的作用就是向编译器提供如何编译程序的信息。实际上,这些标签并没有被编译到生成的 SWF 文件中,而只是告诉编译器如何生成 SWF 文件。

adobe 官网 http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html详细讲解了 16 meta 的使用,简单如下表所示。

Tag

Description

[ArrayElementType]

Defines the allowed data type of each element of an Array.

[Bindable]

Identifies a property that you can use as the source of a data binding expression.

[DefaultProperty]

Defines the name of the default property of the component when you use the component in an MXML file.

[Deprecated]

Marks a class or class element as deprecated so that the compiler can recognize it and issue a warning when the element is used in an application.

[Effect]

Defines the MXML property name for the effect.

[Embed]

Imports JPEG, GIF, PNG, SVG, and SWF files at compile time. Also imports image assets from SWC files.

[Event]

Defines the MXML property for an event and the data type of the event object that a component emits.

[Exclude]

Omits the class element from the Flex Builder tag inspector. The syntax is as follows:[Exclude(name="label", kind="property")]

[ExcludeClass]

Omits the class from the Flex Builder tag inspector. This is equivalent to the @private tag in ASDoc when applied to a class.

[IconFile]

Identifies the filename for the icon that represents the component in the Insert bar of Adobe Flex Builder.

[Inspectable]

Defines an attribute exposed to component users in the attribute hints and Tag inspector of Flex Builder. Also limits allowable values of the property.

[InstanceType]

Specifies the allowed data type of a property of type IDeferredInstance.

[NonCommittingChangeEvent]

Identifies an event as an interim trigger.

[RemoteClass]

Maps the ActionScript object to a Java object.

[Style]

Defines the MXML property for a style property for the component.

[Transient]

Identifies a property that should be omitted from data that is sent to the server when an ActionScript object is mapped to a Java object using [RemoteClass].

本人认为,这其中常用的 Bindable Embed RemoteClass 3 种(本人是从开发业务程序角度来考虑, effect ui 效果就暂且忽略了)。

1、 Bindable 标签

Bindable 标签应该是使用率最高的标签,其功效就是将某个变量或者属性绑定到目标对象上,比如业务应用经常要操作 datagrid ,此时就需将变量绑定到 datagrid.dataprovider 上,通过变量操作来显示 datagrid 的数据变动。

[ Bindable ]

private var transWayLists:ArrayCollection;

...

transWayLists }"/>

2、 RemoteClass 标签

该标签用以映射 flex object java object ,因此在写 flex 程序与 java 程序交互之时特别有用,比如 flex 登录程序总需发送登录信息到 java 登录服务,然后 java 登录服务通过验证返回登录用户信息,此时就需 flex user 映射到 java user ,如下:

flex

[ Bindable ]

[RemoteClass ( alias="com. marcus .User" )]

public class User

{

public var userId:String;

public var businessId:String;

public var userName:String;

public var password:String;

public var passTimeout:Date;

...

}

java:

package com.marcus;

import java.util.Date;

public class User {

private String userId;

private String businessId;

private String userName;

private String password;

private Date passTimeout;

...

}

3、 Embed 标签

该标签用以嵌入 jpg 等资源文件,并在编译的时候生成到 swf 文件中,因此嵌入资源文件过大时,会影响 swf 加载速度。

[Embed(source='home.png')] // 绑定图片home.pnghome_icon

private var home_icon:Class;

4、 ArrayElementType 标签

该标签用以标识数组中元素的数据类型,该 meta tag 并未列入本人的常用 meta tag 之一,为何还要强调的原因就是本人认为 ArrayElementType 标签就是一个鸡肋标签,狗屁不是,建议大家慎用。

你可能感兴趣的:(Flex,ActionScript,Adobe,XML,应用服务器)