【问题标题】:button skin not showing up with addElement();addElement() 未显示按钮皮肤;
【发布时间】:2012-03-26 15:17:03
【问题描述】:

我在 actionscritpt 中创建了一个扩展 spark.components.Button 的类,因为我将在运行时加载一堆按钮。我有一个 SkinnableContainer.mxml 文件,火花按钮将被加载到该文件中。当我在该 mxml 文件中使用 addElement() 方法时,我的按钮的自定义外观不会显示。

//in the SkinnableContainer.mxml file
public function displayButton(button:Button):void
{
     addElement(button);
}

但是,如果在同一个 SkinnableContainer.mxml 文件中,我将其放入 via

<mybuttons:CustomButton x="73" y="4"/>

皮肤显示得很好。

我想可能是因为在调用 loadStyleDeclarations 后添加了按钮,这可能是问题所在,所以我调用了

  styleManager.loadStyleDeclarations(skin, true, true, ApplicationDomain.currentDomain); 

在我添加按钮元素后,按钮仍然没有皮肤。

有什么想法吗?

【问题讨论】:

  • 在 displayButton 方法中,您将参数键入为 Button 而不是 CustomButton,您确定将 CustomButton 传递给它吗?将元素添加到显示树后不需要重新加载样式声明,只要注册了样式并且组件实现了样式的使用,就应该应用它们。
  • 谢谢,我会试一试

标签: actionscript-3 flex4 flash-cs5


【解决方案1】:

正如 shaunhusain 所说,您的方法是寻找火花按钮,而不是我假设处理蒙皮的 CustomButton。

不管怎样,在您的方法中,您可以使用 setStyle 将您的皮肤应用到传递的按钮

public function displayButton(button:Button):void
{
  button.setStyle("skinClass", your.button.SkinClass);
  addElement(button);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    相关资源
    最近更新 更多