3 Replies Latest reply on Apr 5, 2010 8:54 AM by David_F57

    Possible to pass parameters to a skin?

    david.t.lanton

      I have 2 skins, almost identical, but differ in 1 small way that can be accounted for if I could pass a Boolean to the skin while assigning it to the host component (a button).

       

               <s:Button skinClass="MyBtnSkin" />

       

      Is there a way while assigning the skin to the button, I could also pass a parameter to the skin somehow?

        • 1. Re: Possible to pass parameters to a skin?
          David_F57 Level 5

          Hi,

           

          You can bind to flex globals so that if a value changes so does the skin - the following is a simple (read quick n dirty) example of changing a panels skin title color

           

          http://gumbo.flashhub.net/skintest/ source enabled

           

           

          The only change to the standard skin is

           

          - import mx.core.FlexGlobals;

           

          and

           

          <s:GradientEntry color="{FlexGlobals.topLevelApplication.colChange}" />  (around line 191).

           

           

          If you create a custom component its better as any variables declared in that custom component become available thru the hostComponent declaration

           

           

          David.

          • 2. Re: Possible to pass parameters to a skin?
            shawnb81 Level 1

            You could use globals, but that would be pretty horrible OO design.

             

            The proper way to do it would be to create a subclass for whatever component you need, declare any additional properties or style tags you need, and then reference them using "hostComponent.property" or "hostComponent.getStyle('property')".

             

            It's not totally necessary to create a custom component though, you can simply set a style, and get it from within the skin. But then you won't get code hinting, and the style will need to be added through actionscript and not in the mxml component itself.

            • 3. Re: Possible to pass parameters to a skin?
              David_F57 Level 5

              Hi,

               

              I agree that globals aren't the best way to go(but that was the question asked ) which is why I mentioned custom components, the thing is its actually quicker to extend a component(and much more coder friendly) rather than play with styles.

               

               

              David.