flex 常用元标签讲解

<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!-- [if gte mso 10]> <mce:style><!-- /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} table.MsoTableGrid {mso-style-name:网格型; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; border:solid windowtext 1.0pt; mso-border-alt:solid windowtext .5pt; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-border-insideh:.5pt solid windowtext; mso-border-insidev:.5pt solid windowtext; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!-- [endif]-->

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].

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

<!-- [if !supportLists]-->1、 <!-- [endif]-->Bindable 标签

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

[ Bindable ]

private var transWayLists:ArrayCollection;

...

<mx:AdvancedDataGrid dataProvider="{ transWayLists }"/>

<!-- [if !supportLists]-->2、 <!-- [endif]-->RemoteClass 标签

该标签用以映射 flex objectjava 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;

...

}

<!-- [if !supportLists]-->3、 <!-- [endif]-->Embed 标签

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

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

private var home_icon:Class;

<!-- [if !supportLists]-->4、 <!-- [endif]-->ArrayElementType 标签

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值