简体   繁体   中英

How can I retrieve all style properties applied to a flex UIComponent?

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 (ie 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

So my initial research shows that there is no direct function call or list for retrieving an array of style properties.

I think the only way is to check the cascading arrays for the property name.

Code for getStyle for reference:

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM