【问题标题】:Flex when mxml described component initialise it's mxml described propertiesFlex 当 mxml 描述的组件初始化它是 mxml 描述的属性
【发布时间】:2011-09-04 01:32:00
【问题描述】:

我正在尝试重写一个 Button 类,我有一些属性我希望直接使用组件的 mxml 描述进行初始化,例如:

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

当所有带有 mxml 描述的属性都用它们的值完全初始化时,哪个函数被触发(为了覆盖它)?

【问题讨论】:

    标签: apache-flex actionscript-3 properties initialization mxml


    【解决方案1】:

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

    • createChildren() — 调用一次以创建和添加子组件。
    • measure() 在layout过程中调用以计算组件尺寸。
    • updateDisplayList() 具有真实组件未缩放的宽度和高度作为参数。很明显这种方法便于孩子的定位。
    • commitProperties() 是我建议您重写的方法,以便应用不需要组件大小来应用的属性值。

    因此,在您的情况下,它可以是 updateDisplayList()commitProperties()。我推荐你下面的代码sn-ps:

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

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-27
      • 2011-10-20
      • 1970-01-01
      • 2010-12-23
      相关资源
      最近更新 更多