MXML AS3 设置按钮默认高度,允许覆盖
MXML AS3 Set Button Default Height, Allow Override
我有一个扩展 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" />
我有一个扩展 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" />