commitProperties ()
方法
override protected function commitProperties():void
處理對組件設定的屬性。此方法是一種進階方法,可在建立 UIComponent 的子類時覆蓋。
您無需直接調用此方法,當您使用 addChild() 方法向容器中添加組件時,或調用組件的 invalidateProperties() 方法時,Flex 都會調用 commitProperties() 方法。應在調用 measure() 方法之前調用 commitProperties() 方法。這允許您設定 measure() 方法可能會用到的屬性值。
一些組件的屬性可能會影響需要建立的子物件的數目或種類,也有些組件的屬性彼此之間會相互影響(例如 horizontalScrollPolicy 和 horizontalScrollPosition 屬性)。通常,最好在啟動時一次性處理所有這些屬性以避免重複工作。
範例:
一些組件的屬性可能會影響需要建立的子物件的數目或種類,也有些組件的屬性彼此之間會相互影響(例如 horizontalScrollPolicy 和 horizontalScrollPosition 屬性)。通常,最好在啟動時一次性處理所有這些屬性以避免重複工作。
import flash.filters.GlowFilter;
import flash.text.TextFormat;
import mx.controls.Label;
public class MyLabel extends Label
{
private var _color:uint;
public function MyLabel()
{
super();
}
override protected function commitProperties():void
{
super.commitProperties();
var glow:GlowFilter = new GlowFilter(_color,1,2,2,255,1,false);
var arr:Array = new Array();
arr.push(glow);
this.textField.filters = arr;
}
public function set stroke(color:uint):void
{
_color=color;
}