2012-08-16 23 views
2

我想知道什么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声明更具体。

此图片给你的萤火虫如何给你选择的对象样式信息的想法:

enter image description here

例如:

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"); 
+0

我从来没有试过才知道,在运行时间所有风格的继承,但肯定有一种方法可以做到这一点。无论如何,我建议您阅读Adobe Flex 4.6帮助文档:http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7e83.html。 在那里,它解释了如何应用继承以及它应该如何工作。 这可以给你一个线索来实现一些适合你的需求的东西。 – Lasneyx 2012-09-12 06:58:42

回答

0

您可以创建package mx.styles。复制到此包文件StyleProtoChain,CSSStyleDeclaration,CSSMergedStyleDeclaration并实现您在此类中需要的功能。

例如可以覆盖

override mx_internal function addStyleToProtoChain(chain:Object, 
              target:DisplayObject, 
              filterMap:Object = null):Object 
{ 
    // If we have a local style, then add only it to the chain. It will 
    // take are of adding its parent to the chain. 
    // If then is no style, but a parentStyle, then add the parent Style 
    // to the chain. 
    if (style) 
     return style.addStyleToProtoChain(chain, target, filterMap); 
    else if (parentStyle) 
     return parentStyle.addStyleToProtoChain(chain, target, filterMap); 
    else 
     return chain; 
} 
+0

我不知道该怎么做。我正在寻找一些代码,创建和对象,显示我这样(上面张贴)。 – 2012-09-12 19:42:27

0

可以通过使用静态ObjectUtil.toString()方法来显示组件的inheritingStyles属性调试组件的继承样式。

演示: http://blog.flexexamples.com/2007/12/24/displaying-a-combobox-controls-inherited-styles-in-flex/

<mx:Script> 
     <![CDATA[ 
      import mx.utils.ObjectUtil; 

      private function init():void { 
       textArea.text = ObjectUtil.toString(comboBox.inheritingStyles); 
      } 
     ]]> 
    </mx:Script> 
+0

显示此对象具有的样式和值,但不显示如何查找样式继承(值来自或拥有该值)。 – 2012-09-17 20:15:00