2011-05-28 124 views
0

我试图重写一个Button类,我有我直接想与组件的MXML描述初始化,像一些属性:了Flex MXML描述组件初始化它的MXML描述性

<sl:TMyButton id="btnX" x="168" y="223" width="290" label="Button" myproperty1="10" myproperty2="101" myproperty3="4"/> 

这功能被触发(以覆盖它)时使用MXML描述的所有属性完全与他们的价值观初始化?

回答

5

Flex组件have 4 methods in protected namespace which should be overridden to solve different tasks

  • createChildren() - 调用一个时间来创建并添加子。
  • measure()呼吁在布局计算组件大小的过程中。
  • updateDisplayList()具有实分量未缩放的宽度和高度作为参数。很明显,这种方法很方便儿童的定位。
  • commitProperties()是我建议你重写的方法,以便应用不需要使用组件大小的属性值。

所以在你的情况下,它可以是updateDisplayList()commitProperties()。我建议你下面的代码片段:

private var myproperty1Dirty:Boolean; 
private var _myproperty1:String; 
public function set myproperty1(value:String):void 
{ 
    if (_myproperty1 == value) 
     return; 
    _myproperty1 = value; 
    myproperty1Dirty = true; 
    // Postponed cumulative call of updateDisplayList() to place elements 
    invalidateDisplayList(); 
} 

private var myproperty2Dirty:Boolean; 
private var _myproperty2:String; 
public function set myproperty2(value:String):void 
{ 
    if (_myproperty2 == value) 
     return; 
    _myproperty2 = value; 
    myproperty2Dirty = true; 
    // Postponed cumulative call of commitProperties() to apply property value 
    invalidatePropertues(); 
} 

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void 
{ 
    super.updateDisplayList(unscaledWidth, unscaledHeight); 
    if (myproperty1Dirty) 
    { 
     // Perform children placing which depends on myproperty1 changes 
     myproperty1Dirty = false; 
    } 
} 

override protected function commitProperties():void 
{ 
    super.commitProperties(); 
    if (myproperty2Dirty) 
    { 
     // Apply changes of myproperty2 
     myproperty2Dirty = false; 
    } 
} 

希望这有助于!

+0

它帮助我解决:)非常感谢你的谜语。 :) – 2011-05-28 19:31:29

+0

不客气! – Constantiner 2011-05-28 19:31:57