我不确定我在这里遗漏了什么。在我的 Flex 元素中有一些自定义 namespace ,以及像“mx”和“s”这样的常用 namespace 。
我想对自定义命名空间中的样式使用 getStyleDeclaration,但我似乎无法找出正确的语法。
我的样式表部分看起来像这样:
.WidgetTitle
{
fontWeight: bold;
}
myNamespace|ScaleBar
{
right: 10;
bottom: 20;
left: NaN;
top: NaN;
}
如果我尝试在“.WidgetTitle”上使用 getStyleDeclaration,它工作正常:
trace(styleManager.getStyleDeclaration(".WidgetTitle")); // output: [object CSSStyleDeclaration]
如果我对自定义命名空间尝试相同的操作,它会输出 null:
trace(styleManager.getStyleDeclaration("myNamespace|ScaleBar")); // output: null
我已经尝试了所有我能想到的组合:“myNamespace|ScaleBar”、“myNamespace.ScaleBar”、“myNamespace ScaleBar”等,但我找不到任何关于如何执行此操作的文档。
谢谢
最佳答案
myComps 包中的自定义按钮:
package myComps
{
import spark.components.Button;
public class MyButton extends Button
{
}
}
在应用类中:
<fx:Style>
@namespace myComps "myComps.*";
myComps|MyButton{
color: #ff0000;
fontSize: 30;
}
</fx:Style>
和
<fx:Script><![CDATA[
private function _creationCompleteHandler():void
{
var css:CSSStyleDeclaration = styleManager.getStyleDeclaration("myComps.MyButton");
trace("fontSize", css.getStyle("fontSize"));
trace("color", css.getStyle("color"));
}
]]></fx:Script>
追踪:
[trace] fontSize 30
[trace] color 16711680
对我来说很管用。
关于css - 在 Flex 4.5 中,如何在自定义 CSS namespace 中对样式使用 getStyleDeclaration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8825182/