2 Replies Latest reply on Nov 10, 2009 11:51 AM by ghempton

    Why Are Styles Relative to Components and Not Skins?

    ghempton

      I am trying to make a skin for a Button that consists of nothing more than an image. I want to make a generic skin that I can reuse and just have a style for the source of the image. The problem, however, is that the [Style] metadata tags exist on the Button component and not on the skin. Thus, since Button does not have a "source" style property defined, I cannot do something like this:

       

      <s:Button skinClass="{ImageButtonSkin}" source="@Embed('/assets/images/gripper.png')" />

       

      Since there is no "source" style for button this results in a compile error. It seems to me like this shouldn't be an issue. Since all of the presentation is inside of the skin, shouldn't the styles be defined on the skin instead of the component? If the reason for not doing this is backwards compatibility related, then it seems like the compiler could just pull from both places.

       

      As it stands, it is very cumbersome to have to create an entire subclass of Skin just to change the source of an image. Alternatively, I could subclass button to have the style property declared, but that seems very inelegant. Thoughts?

        • 1. Re: Why Are Styles Relative to Components and Not Skins?
          rfrishbe Level 3

          Hey Gordon,

           

          What you're doing is correct--it's an unfortunate limit of our current inline CSS mechanism.  For now, you'll have to create a new subclass to declare the new style metadata or you'll have to set the property using other (non-inline) CSS, like:

           

          s|Button

          {

          source: Embed(...);

          }

           

          Ideally, the compiler wouldn't just look at the style metadata declared on the component, but it would also look at the style metadata declared on all Skins for that component as well.  Or we could introduce a new inline CSS syntax, like:

           

          <s:Button style="source: @Embed(...); skinClass: ClassReference(ImageButtonSkin)" />

           

          Hopefully we will get to these enhancements soon, but probably not for Flex 4.0.

           

          -Ryan

          • 2. Re: Why Are Styles Relative to Components and Not Skins?
            ghempton Level 1

            Good to know what I am doing is correct. I think the inline "style" attribute you proposed seems the most appealing, if not only for its congruency with xhtml.

             

            Alternatively, since really what styles boil down to are just methods for parameterizing skins, it could be cool if there was something like the following:

             

            <s:Button>

             

                 <s:skin>

                      <local:ImageButtonSkin source="@Embed(...);" />

                 </s:skin>

             

            </s:Button>

             

            Or maybe have the have the skin style attributes be defined in their own namespace, e.g.:

             

            <s:Button  myskin:source="@Embed(...);" />

             

            That way the compiler wouldn't have to make 2 passes to guess at what skin is applied to the component, it would just have to lookup the skin implementation corresponding to the namespace.

             

            Just randomly brainstorming, thanks for your response.