MXML AS3设置按钮默认高度,允许覆盖



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

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

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

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

我该怎么做?

这段代码对我有效。

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" />

最新更新