简体   繁体   English

按钮外观没有通过addElement()出现;

[英]button skin not showing up with addElement();

I created a class in actionscritpt that extends the spark.components.Button, as I will be loading a bunch of buttons at runtime. 我在actioncritpt中创建了一个扩展spark.components.Button的类,因为我将在运行时加载一堆按钮。 I have a SkinnableContainer.mxml file that the spark buttons will be loaded into. 我有一个SkinnableContainer.mxml文件,该按钮将被加载到其中。 When I use the addElement() method within that mxml file like so my custom skin for my button does not show. 当我在该mxml文件中使用addElement()方法时,这样按钮的自定义外观就不会显示。

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

however if in that same SkinnableContainer.mxml file I drop it in via 但是,如果在同一个SkinnableContainer.mxml文件中,则通过

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

the skin shows just fine. 皮肤显示就好了。

I thought maybe since the button was being added after I had called the loadStyleDeclarations, this might be the issue, so I called the 我以为可能是因为在调用loadStyleDeclarations之后添加了按钮,所以这可能是问题所在,所以我将其称为

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

after I added the button element and the button still does not skin. 添加按钮元素后,按钮仍然没有外观。

Any ideas? 有任何想法吗?

As shaunhusain said your method is looking for a spark Button not your CustomButton that I assume handles the skinning. 正如shaunhusain所说,您的方法是在寻找一个火花按钮,而不是我认为处理外观的CustomButton。

Regardless of this, inside your method you can apply your skin to the passed button using setStyle 无论如何,在您的方法内部,您可以使用setStyle将皮肤应用于传递的按钮

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM