【问题标题】:How can I retrieve all style properties applied to a flex UIComponent?如何检索应用于 flex UIComponent 的所有样式属性?
【发布时间】:2012-12-11 23:55:24
【问题描述】:

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

例如,我有一个 BorderContainer 并且 CSS 给了它 背景颜色:#869ca7; 背景Alpha:0.5;

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

我尝试了两种方法,感觉很接近但实际上无法检索列表。

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

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

感谢您提供任何可以帮助我的见解。

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

【问题讨论】:

  • 只是做了一些搜索,因为我在文档中找不到明显的解决方案,偶然发现这应该有帮助,在帖子中有一些 AS3 用于获取所有样式:codingforums.com/showthread.php?t=187845

标签: css actionscript-3 apache-flex mxml


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-26
    • 2021-07-23
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多