0

I want the list of all style properties/values applied to a UIComponent's selector via css but I can't seem to find a list of them anywhere.

For example, I have a BorderContainer and the CSS gives it backgroundColor: #869ca7; backgroundAlpha: .5;

and from an ActionScript function I would like to retrieve the list {backgroundColor:#869ca7, backgroundAlpha:.5}. But in an abstract way that works for all UIComponents (i.e. I can't just call getStyle("backgroundColor");

I've tried two ways and I feel very close but can't actually retrieve the list.

  1. It feels like I should be able to get the list of properties from the UIComponents by using the styleDeclaration property on the UIComponent, but it doesn't seem to show the list of style properties it has.

  2. It also seems like I should be able to get the values by calling "uiComponent.getStyle(_)" but that requires that I already know the property names.

Thank you for any insight you can help me with.

For reference, the CSSStyleDeclaration class: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/CSSStyleDeclaration.html

4

1 回答 1

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;
}
于 2012-12-12T02:51:19.717 回答