Flex中元标签及使用
|
元数据标签是一种特殊的标签,它在代码中的作用就是向编译器提供如何编译程序的信息。 Flex中的元标签列表如下:
[ArrayElementType] 使用ArrayElementType元数据标签可以让你定义数组元素的数据类型。 [ArrayElementType("Number")]
public var arr:Array;
事实上,MXML编译器只针对mxml代码中的ArrayElementType元数据标签的用法进行合理性检查。而对 actionscript代码中的用法不进行合理性检查,通过试验可以知道,ArrayElementType标签此时是无效的。 也就是说,上面的声明是无效的~,只有在MXML里才能正确检查,你可以测试一下: arr.push(1);
arr.push("name"); //并不会报错
Bindable绑定数据的例子 申明变量txt可绑定后,当txt值改变,绑定txt的Label显示的内容也会跟着改变。 <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
[Bindable]
private var txt:String = "Hello world.";
private function init():void
{
changeBtn.addEventListener(MouseEvent.CLICK,function():void{txt="Hello World,Hello World."});
}
]]>
</mx:Script>
<mx:Label x="10" y="10" text="{txt}"/>
<mx:Button x="10" y="36" label="更新数据" id="changeBtn"/>
</mx:Application>
[DefaultProperty("propertyName")] DefaultProperty元数据标签用来将一个单一属性设定为某个类的默认属性。它允许在一个容器标签内设定属性,而不用定义属性的名字。 package myComponents
{
import mx.controls.TextArea;
// 定义一个默认的属性defaultText,下例中的Hello将做为defaultText的值。
[DefaultProperty("defaultText")]
public class TextAreaDefaultProp extends TextArea {
public function TextAreaDefaultProp()
{
super();
}
// Define a setter method to set the text property
// to the value of the default property.
public function set defaultText(value:String):void {
if (value!=null)
text=value;
}
public function get defaultText():String {
return text;
}
}
}
在MXML里使用该组件: <?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:TextAreaDefaultProp>Hello</MyComp:TextAreaDefaultProp>
</mx:Application>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
