开发者

Is there a way to get a list of all skin classes in the current application?

Is there a way to get a list of all the skin classes that are in the current application? I'm using Flex 4.5.1.

Here is the loop that I'm using now to get all the skins,

            for each (var item:Object in styleManager.typeHierarchyCache) {

                for (label in item) {

                    if (label=="spark.components.supportClasses.Skin" ||
                        label=="spark.skins.mobile.supportClasses.MobileSkin") {

                        for (label in item) {
                            name = label.substr(label.lastIndexOf(".")+1);
                            vo = new SkinObject();
                            vo.name = name;
                            vo.qualifiedName = label;
                            dictionary[label] = vo;
                        }
                        break;
                    }

                }

            }

            for each (item in dictionary) {
              开发者_Python百科  array.push(item);
            }

The reason why is because I want to list all the skins in the application and then be able to apply them in real time so I can see what they look like. * I have this working but I was hoping for a better way.


You definitely could iterate through all objects on the screen and see if they're of type SparkSkin. Something like this:

private function findSkins():void
{
    recurseComponent(FlexGlobals.topLevelApplication);
}

private function recurseComponent(parent:UIComponent):void
{
    var child:UIComponent;
    for(var i:uint = 0, len:uint = parent.numElements; i<len; i++)
    {
        child = parent.getElementAt(i) as UIComponent;
        if(child && child is SparkSkin)
        {
            trace("Skin Found!"); // trace whatever you need here
        }
        recurseComponent(child);
    }
}

But be warned that this solution is very expensive since it needs to iterate through all objects on the screen, which can go into several thousands. However, I really don't see what's the purpose of this and would definitely not recommend it other than for debugging/testing purposes.

Edit: Also, this will only work for skins on the display list. Skins mentioned in CSS will not be recognized and I'm fairly sure there's no way of figuring that out short of going through all the css and see if there's a skinClass property. But then it won't catch any default skins or skins set in actionscript or inline mxml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜