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

标签 css actionscript-3 apache-flex mxml

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

例如,我有一个 BorderContainer 并且 CSS 给了它 背景颜色:#869ca7; backgroundAlpha: .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

最佳答案

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

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

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

关于css - 如何检索应用于 flex UIComponent 的所有样式属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13830532/

相关文章:

html - Flex 元素忽略 Firefox 中的填充百分比

html - 出现在 div 中的元素不应该是 : HTML

actionscript-3 - 使用 as3crypto 多次登录 assiSTLy.com

apache-flex - 弹性 : How to create an entirely new component?

java - mule https 入站端点

jQuery fadeToggle 使行背景颜色消失

javascript - 如何强制资源管理器重新加载 Flex 页面(嵌入 HTML 中的 swf)?

actionscript-3 - 什么是最好的 Actionscript3 3D 引擎?

java - Spring-Flex 1.5 示例可以工作吗?

html - Div应该填充高度