我想知道什么CSS样式影响我的UIComponent和从哪里。如何在Flex中查找对象的样式继承?
因此该解决方案将列出样式和给定组件的值:
<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中 - 宋体
颜色 - 0
fontSize的 - 12
textAlign - left
etc
然后我可以找出风格越来越这是一个从价值:
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声明更具体。
此图片给你的萤火虫如何给你选择的对象样式信息的想法:
例如:
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");
我从来没有试过才知道,在运行时间所有风格的继承,但肯定有一种方法可以做到这一点。无论如何,我建议您阅读Adobe Flex 4.6帮助文档:http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7e83.html。 在那里,它解释了如何应用继承以及它应该如何工作。 这可以给你一个线索来实现一些适合你的需求的东西。 – Lasneyx 2012-09-12 06:58:42