5 Replies Latest reply on Jul 1, 2009 1:56 PM by garigantua

    Skin colors from variables?

    Handycam Level 1

      My app is shaping up to use several skins.  Not a problem, but I'd like to have a way to reference a global variable for a color used in a skin.

       

      For example, if I have something like

           <!-- layer 3: title bar fill -->
           <s:Rect left="1" right="1" top="1" height="30">
              <s:fill> 
              <s:LinearGradient rotation="90">
              <s:GradientEntry color="0xE8D8B4" alpha="1"/>
              <s:GradientEntry color="0xD3B36D" alpha="1"/>
              </s:LinearGradient>
              </s:fill>
           </s:Rect>
      

       

      I would like to set, in the main app, a pair of variables such as

      [Bindable] public var gradStart:String = "0xE8D8B4"
      

      and then use in the component for the gradient entry.

       

      Is this possible?  What's the syntax?

        • 1. Re: Skin colors from variables?
          garigantua Level 1

          you should be able to do this,

           

           

           <s:GradientEntry color="{gradStart}" alpha="1"/>

           

          but also make the variable private and use getters and setters

           

          oops, just remembered.  Since Skins are component implementations, you would probably have to make your variables, getters, and setters inspectable.

           

          try something like this

           

          
          [Bindable]
          [Inspectable(defaultValue=true)]
          public var gradStart:uint = 0xE8D8B4;
          
          
          

           

          Then modify your variable accordingly

          • 2. Re: Skin colors from variables?
            Handycam Level 1

            I've never used getters and setters.  I will need to look into it.  Thanks.

             

            I tried using

             

            [Bindable]
            public var testColor:String = "0xff0000";

             

            in the main app and then:

             

            color="{FlexGlobals.topLevelApplication.testColor}" in the component.  It did work, surprisingly, except for a warning about not being able to detect changes to testColor.

             

            What I ulitmately need to do is to be able to have all these values in an XML file, load that into an XMLListCollection and then "assign" the colors from that.  What would be ideal is if I could do it right from the list, something like:

             

            [Bindable]

            public var styleList:XMLListCollection; // contains the xml data

             

            then

             

            color="{styleList.window[0].colorValue}"

             

            Any idea if something like this is feasible?

            • 3. Re: Skin colors from variables?
              garigantua Level 1

              If you can't detect changes to the variable, then you would probably have to make sure your arraylistcollection instance is populated before styling, or force styling afterwards.  Getters and setter for me solve some flow problems and binding issues, but can be extra unecessary code if I'm not careful. 

               

              You should be able to do what you described.  It makes sense to me, but I'm not sure.

              • 4. Re: Skin colors from variables?
                Handycam Level 1

                How would I force styling?

                • 5. Re: Skin colors from variables?
                  garigantua Level 1

                  you can look through

                   

                  updateDisplayList()

                  or

                  validateDisplayList()

                   

                  many components and interfaces implement these 2 methods

                   

                  not sure...depends how you have it set up