我想知道哪些 CSS 样式正在影响我的 UIComponent 以及从何处影响。
所以解决方案将列出给定组件的样式和值:
<s:Label id="myLabel" />
<s:Group id="myLabel" fontFamily="Tahoma"/>
<s:Label id="myOtherLabel" />
</s:Group>
然后代码:
var styles:Object = StyleManager.getStyles(myLabel);
trace(styles);
fontFamily - Arial
颜色 - 0
fontSize - 12
textAlign - 左
等
然后我可以找出风格从哪里获得它的价值:
var styleParent:Object = StyleManager.getStyle(myLabel, "fontFamily");
trace(styleParent); // "s|Label" declaration or global?
并且样式查找:
var styleParents:Array = StyleManager.getStyleInheritence(myOtherLabel, "fontFamily");
trace(styleParent); // inline which overrides "s|Group fontFamily" which overrides "s|Label" which overrides global
当我说覆盖时,我的意思是特异性。内联 fontFamily 声明比标签父组上的内联 fontFamily 声明更具体,后者比 s|Label 类型声明更具体,后者比全局 fontFamily 声明更具体。
此图像让您了解 Firebug 如何为您提供所选对象的样式信息:
例如:
var myInheritenceChain:Array = getStylesInheritanceForTarget(myButton);
trace(myInheritanceChain); // output is an array of
[0] {subject:instance, type:inline, styles: {fontFamily:"Noteworthy", color:"blue"}
[1] {subject:spark.components.Button, type:type, styles: {fontFamily:"Bidoni", color:"red"...}
[2] {subject:#myButton, type:id, styles: {fontFamily:"Futura", color:"green"}
[3] {subject:.myClassStyle, type:class, styles: {fontFamily:"Times New Roman", color:"yellow"...}
[4] {subject:global, type:something, styles: {fontFamily:"Helvetica", color:"black"...}
[5] {subject:*, type:something, styles: {fontFamily:"Bauhaus", color:"black"...}
这样您就可以看到为什么以及如何将样式(例如 fontFamily)设置为它设置的值,如下所示:
var myInheritenceChain:Array = getStylesInheritanceForTarget(myButton, "fontFamily");