[Alternative]
【可替換】
標(biāo)明此類可以被參數(shù)中的類替換,版本號說明發(fā)生替換的版本。
[Alternative]和[Deprecated] 不同。如果是【不建議使用】的類,以后的版本可能不可用。而帶有【可替換】標(biāo)簽的類
在以后的版本中仍然可用,只是標(biāo)明有別的類可以用來替換。 例如MX Button就被標(biāo)記了[Alternative]。
[Alternative(replacement="packageAndClassName", since="versionNum")]
這段代碼需要放在類的定義之前。
[ArrayElementType]
【數(shù)組元素類型】
要使得Flex MXML 編譯器對數(shù)組元素進(jìn)行類型檢查,需要使用[ArrayElementType]標(biāo)簽來確定該數(shù)組許可的類型。
[ArrayElementType("String")]
public var newStringProperty:Array;
注意:MXML 編譯器檢查MXML 代碼中數(shù)組的正確使用情況,而不檢查AS代碼中數(shù)組的使用情況。
<MyComp:MyTypedArrayComponent>
<MyComp:newStringProperty>
<fx:Number>94062</fx:Number>
<fx:Number>14850</fx:Number>
<fx:Number>53402</fx:Number>
</MyComp:newStringProperty>
</MyComp:MyTypedArrayComponent>
如果用戶在標(biāo)簽中輸入的是字符串,那么編譯器會報語法錯誤。
參數(shù)可以是AS的任意數(shù)據(jù)類型,例如 String,Number,class或interface。但是必須使用全名,包括package。
[Bindable]
如果某個屬性是某個數(shù)據(jù)綁定表達(dá)式的源時,F(xiàn)lex會在源屬性變化時自動復(fù)制源屬性的值到目標(biāo)屬性。為了讓Flex進(jìn)行這
種復(fù)制操作,必須使用[Bindable]元數(shù)據(jù)標(biāo)簽,并且源屬性需要派發(fā)事件。
例1:
[Bindable]
public var minFontSize:Number = 5;
例2:
[Bindable("textChanged")]
public function get text():String {
return myText;
}
例3:
public function set text(t : String):void {
myText = t;
dispatchEvent( new Event( "textChanged" ) );}
如果你省略了事件名,F(xiàn)lex會自動創(chuàng)建"propertyChange"事件。
如果你把某個屬性作為數(shù)據(jù)綁定源,那么Flex不止監(jiān)視該屬性的變化,還監(jiān)視導(dǎo)向該屬性的屬性鏈的變化。
整個屬性鏈(包含鏈中最終的目標(biāo)屬性)被稱為“綁定屬性鏈”。
<first>{firstName.text}</first>
這個例子中,屬性鏈包含firstName和其text屬性。
你應(yīng)該在該屬性鏈中的任何有名稱的屬性變化時派發(fā)事件。如果該屬性被標(biāo)記為[Bindable],F(xiàn)lex編譯器會代你派發(fā)。
在某些情況下,綁定不會像預(yù)期的那樣自動執(zhí)行:
1,當(dāng)改變一個dataProvider屬性中的整個項時。
dataProvider[i] = newItem
2,當(dāng)某個帶有綁定標(biāo)簽的屬性的子屬性改變時。
[Bindable]
var temp;
// Binding is triggered:
temp = new Object();
// Binding is not triggered, because label not a bindable property
// of Object:
temp.label = foo;
在這個例子中,綁定遇到的問題是temp是個Object。有三種方式可以解決這個問題。
a,Preinitialize the Object。 預(yù)初始化對象。
b,為temp分配一個ObjectProxy;ObjectProxy的所有屬性都是可綁定的。
c,使temp成為帶有l(wèi)abel可綁定屬性的強(qiáng)類型對象。
3,當(dāng)綁定的屬性是Flash Player自動刷新的屬性時,例如mouseX 。
如果綁定的目標(biāo)是UIComponent類,它的executeBindings()方法執(zhí)行所有綁定。
所有的container和control,包括Repeater組件,都擴(kuò)展了UIComponent類。它們的executeChildBindings()方法會同樣的執(zhí)行類型為UIComponent的子項的綁定。所有的容器都繼承自Container類。
綁定沒有按預(yù)期執(zhí)行時,你可以使用這個方法。 當(dāng)某個不會觸發(fā)綁定的改變發(fā)生時,在代碼中加上一句,例如executeChildBindings()這個方法,就可以更新用戶界面。 然而,你應(yīng)該只在綁定確實不會自動觸發(fā)時,才使用executeBindings()方法。
http://www.adobe.com/devnet/flex/articles/databinding_pitfalls.html
這篇文章對綁定講解的很細(xì)致。
[DefaultProperty]
定義組件在MXML文件中使用時的默認(rèn)屬性名稱。
例如:
這樣定義后
// Define the default property.
[DefaultProperty("defaultText")]
public class TextAreaDefaultProp extends TextArea {
}
就可以這樣使用
<MyComp:TextAreaDefaultProp>Hello</MyComp:TextAreaDefaultProp>
[Deprecated]
類或者類元素被標(biāo)記為[Deprecated]標(biāo)明該類或?qū)傩砸驯粡U棄并且不推薦在當(dāng)前版本中使用。不過該類或類元素仍然可以
工作,但編譯器會發(fā)出警告。
mxmlc命令行編譯器支持show-deprecation-warnings編譯選項。當(dāng)為true時,如果你使用了deprecated的元素,編譯器會
發(fā)出deprecation警告。默認(rèn)值為true。
將[Deprecated]標(biāo)簽插入到屬性、方法或類定義之前會將其標(biāo)記為deprecated。例如:
[Deprecated("string_describing_deprecation")]
[Deprecated(message="string_describing_deprecation")]
[Deprecated(replacement="string_specifying_replacement")]
[Deprecated(replacement="string_specifying_replacement", since="version_of_replacement")]
[Event], [Effect] 和 [Style] 也支持deprecation:
[Event(... , deprecatedMessage="string_describing_deprecation")]
[Event(... , deprecatedReplacement="change2")]
[Event(... , deprecatedReplacement="string_specifying_replacement",
deprecatedSince="version_of_replacement")]
[Effect]
此標(biāo)簽定義了組件在MXML狀態(tài)下的效果屬性名稱及觸發(fā)該效果的事件,你可以通過這個屬性給該組件分配一種動態(tài)效果。
動態(tài)效果總是伴隨著觸發(fā)它的事件。該事件可能是鼠標(biāo)點擊事件、獲得焦點事件或可見事件。動態(tài)效果是指在一段時間發(fā)
生的可視或可聽的變化。
一般在類定義之前或在<fx:Metadata>標(biāo)簽內(nèi)定義[Effect]標(biāo)簽。
[Effect(name="eventNameEffect", event="eventName")]
// Define event corresponding to the effect trigger.
[Event(name="darken", type="flash.events.Event")]
// Define the effect.
[Effect(name="darkenEffect", event="darken")]
class ModalText extends TextArea {
...
}
<fx:Metadata>
[Event(name="darken", type="flash.events.Event")]
[Effect(name="darkenEffect", event="darken")]
</fx:Metadata>
[Embed]
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fce.html
Imports JPEG, GIF, PNG, SVG, and SWF files at compile time. Also imports image assets from SWC files.
This is functionally equivalent to the MXML @Embed syntax, as described in Embedding assets.
[Event]
用此標(biāo)簽定義組件在MXML狀態(tài)下的事件。一般在類定義之前或在<fx:Metadata>標(biāo)簽內(nèi)定義[Event]標(biāo)簽。
[Event(name="eventName", type="package.eventType")]
如
[Event(name="myEnableEvent", type="flash.events.Event")]
public class MyComponent extends UIComponent
{
...
}
或
<fx:Metadata>
[Event(name="myEnableEvent", type="flash.events.Event")]
</fx:Metadata>
[Exclude]
讓Flash Builder標(biāo)簽檢查忽略該類元素。
Omits the class element from the Flash Builder tag inspector.
[Exclude(name="label", kind="property")]
[ExcludeClass]
讓Flash Builder標(biāo)簽檢查忽略該類。等同于ASDoc中的@private標(biāo)簽。
Omits the class from the Flash Builder tag inspector. This is equivalent to the @private tag in ASDoc when applied to a class.
[HostComponent]
用此標(biāo)簽確定Spark 皮膚類的宿主組件。例如:
<Metadata>
[HostComponent("spark.components.Button")]
</Metadata>
加了這個標(biāo)簽,F(xiàn)lex會為此皮膚類創(chuàng)建hostComponent屬性。你可以通過這個屬性在皮膚類內(nèi)部獲取宿主組件實例的公共成員。例如,在Button 皮膚內(nèi),你可以得到Button的樣式的屬性。
[IconFile]
用此標(biāo)簽定義組件在Flash Builder中的Insert欄中的圖標(biāo)的文件名。
支持PNG, GIF, JPEG
[IconFile("MyButton.png")]
public class MyButton extends Button
{
...
}
[Inspectable]
此標(biāo)簽為你的組件的屬性定義了編碼提示信息。規(guī)則如下:
* 組件所有的public屬性都會出現(xiàn)在編碼提示和Flash Builder屬性監(jiān)測器中。如果你想為該屬性添加額
外的信息,例如枚舉值或代表一個文件路徑的String屬性,就為該屬性添加[Inspectalbe]標(biāo)簽及信息。
* 組件的編碼提示和屬性監(jiān)測器公用同樣的數(shù)據(jù)。
* AS組件的編碼提示并不需要metadata,因此你總是能看到符合當(dāng)前作用范圍的屬性提示。Flash
Builder使用public/protected/private和static這些關(guān)鍵字來控制屬性的作用范圍及可顯示的編碼提示。
此標(biāo)簽后必須緊跟屬性變量聲明或其set和get方法:
[Inspectable(attribute=value[,attribute=value,...])]
property_declaration name:type;
[Inspectable(attribute=value[,attribute=value,...])]
setter_getter_declarations;
Property | Type | Description |
---|---|---|
category | String | 將屬性歸納入FB用戶界面的屬性監(jiān)測器中的子類別中。默認(rèn)類別是 "Other" . 可以歸類為"Common" , "Effects" , "Events" , "Layout Constraints" , "Size" , "Styles" , "Text", or "Other" . |
defaultValue | String or Number | 設(shè)置屬性的初始值。默認(rèn)值為屬性的定義值。 |
enumeration | String | 為屬性定義一組以逗號分隔的合法值。該屬性只可以取這些值。例如:item1 ,item2 ,item3 . 注意中間沒有空格。這些值會出現(xiàn)在代碼提示及屬性檢測器中。如果你定義了Boolean類型變量,F(xiàn)B會自動顯示true和false,不需要你自己設(shè)置。 |
environment | String | environment=none :可檢測屬性不允許出現(xiàn);environment=Flash:只有Flash Builder可用; (environment=MXML :只有Flex可用,F(xiàn)lash Builder也不可用。 |
format | String | 當(dāng)編輯該屬性值時使用的編輯器類型。 例如,對于Number類型的屬性,你可以設(shè)置format="Color"來讓FB在你設(shè)置屬性值時打開顏色編輯器。一般的值為"Length" , "Color" , "Time" , "EmbeddedFile" 和"File" . |
listOffset | Number | 設(shè)定List值中的默認(rèn)索引。 Specifies the default index into a List value. |
name | String | 設(shè)定屬性的顯示名稱。例如,F(xiàn)ontWidth。如果沒設(shè)定,會使用屬性名,例如_fontWidht. |
type | String | 指定類型的指定器。如果省略,會使用屬性的類型。 下列值可?。?/p>
如果類型是Array,你必須列出Array的可用值。 |
variable | String | 指定此參數(shù)綁定的變量。 |
verbose | Number | 表明此屬性只有在用戶指明包含verbose(詳細(xì)的)屬性時才在FB用戶界面中出現(xiàn)。如果未設(shè)定,則默認(rèn)顯示該屬性。 |
例如:
[Inspectable(defaultValue=true, verbose=1, category="Other")] public var myProp:Boolean;
[InstanceType]
大概主要用于創(chuàng)建模板組件。
// Define a deferred property for the top component. [InstanceType("mx.controls.Label")] public var topRow:IDeferredInstance;
[NonCommittingChangeEvent]
此標(biāo)簽定義了一種折中事件,這種事件不會引起Flex數(shù)據(jù)驗證。通常用于經(jīng)常變化但又不需要每次都進(jìn)行數(shù)據(jù)驗證的屬性。
例如,你給一個TextInput組件的text屬性綁定了某個驗證器。text屬性會在每次鍵盤輸入事件時改變,但你只是希望在用戶按下Enter鍵或移除焦點時進(jìn)行數(shù)據(jù)驗證。此類型事件可以使你分派改變事件但不出發(fā)驗證。
[NonCommittingChangeEvent("event_name")]
下例中,組件在每次用戶鍵盤輸入時都分派change事件,但這個change事件并沒有引發(fā)數(shù)據(jù)綁定或數(shù)據(jù)驗證。當(dāng)用戶完成數(shù)據(jù)輸入并點擊Enter鍵時,組件廣播valueCommit事件來出發(fā)數(shù)據(jù)綁定和數(shù)據(jù)驗證。
[Event(name="change", type="flash.events.Event")]
class MyText extends UIComponent {
...
[Bindable(event="valueCommit")]
[NonCommittingChangeEvent("change")]
function get text():String {
return getText();
}
function set text(t):void {
setText(t);
// Dispatch events.
}
}
[RemoteClass]
用此標(biāo)簽將類注冊到Flex,F(xiàn)lex會在用AMF格式序列化類實例時保留類型信息。需要在類定義之前插入此
標(biāo)簽。
還可以在客戶端程序中用此標(biāo)簽代表某個服務(wù)端Java對象:
[RemoteClass(alias=" ")]
這樣可以創(chuàng)建直接映射到Java對象的AS對象。需要在alias值中賦予Java類的全名。
[RichTextContent]
如果一個屬性是String類型,編譯器會自動試著把其MXML中的值轉(zhuǎn)為String類型。如果屬性類型是*、
Object或Array,編譯器在默認(rèn)情況下會試圖將其轉(zhuǎn)換為適當(dāng)?shù)臄?shù)據(jù)類型。使用此標(biāo)簽可以讓編譯器始終
將該屬性MXML中的值轉(zhuǎn)為String。需要在屬性定義前插入此標(biāo)簽。
[RichTextContent]
例如,spark.components.TextArea 和 spark.primitives.RichText類的content屬性被作為Object輸入
。但如果使用了此標(biāo)簽,那些值就會始終被作為String類型。
數(shù)據(jù)綁定語法中的花括號{},at符號@都對此標(biāo)簽有效。
[SkinPart]
不解。。。
Define a property of a component that corresponds to a skin part. For more information, see SkinPart
metadata tag.
[SkinState]
定義皮膚中的狀態(tài)。
Defines the view states that a component’s skin must support. For more information, see SkinState metadata
tag.
[Style]
定義樣式。
插入到類定義前或MXML中的<fx:Metadata>中。
Defines the MXML property for a style property for the component. For more information on using the [Style]
metadata tag, see Style metadata tag.
[SWF]
在AS中定義main application的屬性。在MXML中一般在<s:Application>標(biāo)簽中定義。
Specifies attributes of the application when you write the main application file in ActionScript. For more
information, see SWF metadata tag.
[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]. For more information, see Transient metadata tag.