开发者

Flex when mxml described component initialise it's mxml described properties

I am trying to override a Button class, i have a few properties which i wish directly initialise with the mxml description of the component, like :

开发者_如何学JAVA<sl:TMyButton id="btnX" x="168" y="223" width="290" label="Button" myproperty1="10" myproperty2="101" myproperty3="4"/>

which function is triggered ( in order to override it ) when all properties with mxml description is fully initialised with their values ?


Flex components have 4 methods in protected namespace which should be overridden to solve different tasks:

  • createChildren() — calls one time to create and add subcomponents.
  • measure() called in process of lay outing to calculate components size.
  • updateDisplayList() has real component unscaled width and height as parameter. It is obvious this method is convenient for positioning of children.
  • commitProperties() is the method I suggest you to override in order to apply properties values which don't need component size to apply.

So in your case it can be updateDisplayList() or commitProperties(). I recommend you the following code snippets:

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;
    }
}

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜