nice approach!!

On 6/13/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:

  Hi Muzak,

Manish and I just had a conversation on flexcoders;

Passing "false" to setStyleDeclaration() in a component's static
initialiser

I can never get the url from gmail but, that is the subject.

Basically do this in your static initializer.

This is what I do with all of my components,

Creation method::


    public static function
createSelector(selectorName:String):CSSStyleDeclaration
    {
        var selector:CSSStyleDeclaration =
            StyleManager.getStyleDeclaration(selectorName);

        if (!selector)
        {
            selector = new CSSStyleDeclaration();
            StyleManager.setStyleDeclaration(selectorName, selector,
false);
        }

        return selector;
    }


In the custom component class::


    private static function initStyles():Boolean
    {
        var styles:CSSStyleDeclaration =
            FSCollectionDefaults.createSelector("TaskListFX");

        styles.defaultFactory = function():void
        {
            this.borderStyle = "solid";
            this.offsetBorder = true;
            this.paddingBottom = 3;
            this.paddingLeft = 3;
            this.paddingRight = 3;
            this.paddingTop = 3;
            this.verticalGap = 6;
        }
        return true;
    }


Creating a default factory does this, instead of using setStyle() you
create the defaults to the defaults.

setStyle() adds the values to the overrides object. Using the
defaultFactory function creates the low level defaults and then you can call
setStyle on the selector and it will override the default factories styles.


I have never had a problem with this technique.

Peace, Mike

On 6/13/07, Muzak <[EMAIL PROTECTED] > wrote:
>
>   I just ran into the following issue and was wondering how others solve
> this.
>
> When creating a component and setting default styles, you use a static
> method and check for the existance of a StyleDeclaration.
>
> private static function initStyles():Boolean {
> var css:CSSStyleDeclaration = StyleManager.getStyleDeclaration
> ("MyComponent");
> if (!css) {
> css = new CSSStyleDeclaration();
> css.setStyle("tileColors", [0x000000, 0xFFFFFF]);
> StyleManager.setStyleDeclaration("StyleComponent", css, false);
> }
> return true;
> }
>
> This works fine as long as there is no CSS style defined in MXML
>
> Let's say I have the following mxml:
>
> <mx:Style>
> StyleComponent {
> }
> </mx:Style>
>
> <controls:StyleComponent id="_comp" />
>
> As you can see, there is a style for the component defined in CSS, but
> no styles are defined.
> So because a CSSStyleDeclaration will be defined when the static
> initStyles method is invoked, default styles (tileColors) will not
> be set, in other words, it never reaches past the if(!css) part.
>
> So how and, more important, where (in which method) does one check if
> styles have actually been defined and if no default values
> exist, set them.
>
> regards,
> Muzak
>
>


--
Teoti Graphix
http://www.teotigraphix.com

Blog - Flex2Components
http://www.flex2components.com

You can find more by solving the problem then by 'asking the question'.




--
j:pn
http://www.lennel.org

Reply via email to