【问题标题】:MXML AS3 Set Button Default Height, Allow OverrideMXML AS3 设置按钮默认高度,允许覆盖
【发布时间】:2016-04-11 03:19:05
【问题描述】:

我有一个扩展 spark.components.Button 的组件

我将这个新组件用于我在应用程序中使用的所有按钮。现在我想为按钮设置一个默认高度,这些是规格

  • 默认情况下,按钮在 AS3 上设置了默认高度。
  • 在 mxml 上,如果设置了高度值,它将覆盖默认高度。

尝试设置 $this->height 值,但不允许覆盖默认值。

我该怎么做?

【问题讨论】:

  • 也许可以发布一些代码来了解您在那里做什么。
  • 检查我的编辑..这里没有涉及太多编码..只是想了解如何做到这一点。

标签: actionscript-3 flash button mxml


【解决方案1】:

这段代码对我有用。

public class CustomButton extends Button
{
    private static var defaultHeight:Number = 50;

    public function CustomButton()
    {
        super();
    }

    override protected function createChildren(): void
    {
        trace("height:"+this.explicitHeight);   // If didn't set height at MXML, explicitHeight returns NaN.
        if (!this.explicitHeight)
        {
            this.height = defaultHeight;
        }

        super.createChildren();
    }

}

<local:CustomButton x="0" y="0" label="Button1" height="30" />
<local:CustomButton x="0" y="100" label="Button2" />

【讨论】:

    猜你喜欢
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    • 2015-06-30
    相关资源
    最近更新 更多