我想知道什麼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