Flex 当 mxml 描述的组件初始化它的 mxml 描述的属性时

发布于 2024-11-10 10:07:38 字数 263 浏览 6 评论 0原文

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

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

当具有 mxml 描述的所有属性完全初始化时,会触发哪个函数(以便覆盖它)他们的价值观?

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 :

<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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月隐月明月朦胧 2024-11-17 10:07:38

Flex 组件 中有 4 个方法protected 命名空间应被覆盖以解决不同的任务

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

希望这有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文