如何检索应用于flex UIComponent的所有样式属性?

时间:2012-12-11 23:55:24

标签: css actionscript-3 flex mxml

我希望通过css将所有样式属性/值的列表应用于UIComponent的选择器,但我似乎无法在任何地方找到它们的列表。

例如,我有一个BorderContainer,CSS给它     backgroundColor:#869ca7;     backgroundAlpha:.5;

从ActionScript函数中我想检索列表{backgroundColor:#869ca7,backgroundAlpha:.5}。但是以一种适用于所有UIComponents的抽象方式(即我不能只调用getStyle(“backgroundColor”);

我尝试了两种方式,但我觉得非常接近但实际上无法检索列表。

  1. 感觉我应该能够通过使用UIComponent上的styleDeclaration属性从UIComponents获取属性列表,但它似乎没有显示它具有的样式属性列表。

  2. 似乎我应该能够通过调用“uiComponent.getStyle( _ )”来获取值,但这需要我已经知道属性名称。

  3. 感谢您提供帮助我的任何见解。

    供参考,CSSStyleDeclaration类: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/CSSStyleDeclaration.html

1 个答案:

答案 0 :(得分:1)

所以我的初步研究表明,没有直接的函数调用或列表来检索样式属性数组。

我认为唯一的方法是检查级联数组的属性名称。

getStyle代码供参考:

public function getStyle(styleProp:String):*
{
    var o:*;
    var v:*;

    // First look in the overrides, in case setStyle()
    // has been called on this CSSStyleDeclaration.
    if (overrides)
    {
        // If the property exists in our overrides, but 
        // has 'undefined' as its value, it has been 
        // cleared from this stylesheet so return
        // undefined.
        if (styleProp in overrides &&
            overrides[styleProp] === undefined)
            return undefined;

        v = overrides[styleProp];
        if (v !== undefined) // must use !==
            return v;
    }

    // Next look in the style object that this CSSStyleDeclaration's
    // factory function produces; it contains styles that
    // were specified in an instance tag of an MXML component
    // (if this CSSStyleDeclaration is attached to a UIComponent).
    if (factory != null)
    {
        factory.prototype = {};
        o = new factory();
        v = o[styleProp];
        if (v !== undefined) // must use !==
            return v;
    }

    // Next look in the style object that this CSSStyleDeclaration's
    // defaultFactory function produces; it contains styles that
    // were specified on the root tag of an MXML component.
    if (defaultFactory != null)
    {
        defaultFactory.prototype = {};
        o = new defaultFactory();
        v = o[styleProp];
        if (v !== undefined) // must use !==
            return v;
    }

    // Return undefined if the style isn't specified
    // in any of these three places.
    return undefined;
}