Flex 4.0 之commitProperties函数的使用

来源:互联网 发布:mac与iphone配合使用 编辑:程序博客网 时间:2024/05/16 04:48
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;
  }

原创粉丝点击