Flex 4 :: StyleManager.getStyleDeclaration() :: take 2
June 25th, 2009Hi,
I need to clear the air here, what I said in my last post seems to be deprecated as of Flex 3. I dug into the auto generated classes and now see how the compiler is initializing classes.
For a type selector in a component it would be something like;
var style:CSSStyleDeclaration = StyleManager.getStyleDeclaration("com.teotigraphix.ui.control.TitleBar");
if (!style)
{
style = new CSSStyleDeclaration(selector);
}
if (style.defaultFactory == null)
{
style.defaultFactory = function():void
{
this.skinClass = com.teotigraphix.ui.skin.tk.TitleBarSkin;
}
}
The key difference from Flex 3 to Flex 4 is the CSSStyleDeclaration can take a string OR a CSSSelector instance. If the argument to the CSSStyleDeclaration is a CSSSelector instance, the CSSStyleDeclaration will automatically register the new css declaration to the StyleManager.
The trick here is that the CSSSelector overrides it's toString() method to return the specific selector name based on it's ancestor and conditions. The style manager still uses the string selectorString in the set declaration method, but if an instance of CSSSelector is passed instead of a string selector name, the toString() method is called on the CSSSelector.
That sounded like a tongue twister.
Mike


