2 Replies Latest reply on May 23, 2011 6:14 PM by Teriath

    Modify skin components at runtime


      I have a button component that has a single image and some color filters to make it change colors for the different states and I need a way to change the image source at runtime based on some data. Is this possible? If not, do I really have to make a custom component just to do this? Because that seems like way too much work for something so simple.

        • 1. Re: Modify skin components at runtime
          drkstr_1 Level 4

          That custom component that is "way to much work" probably would have taken the same amount of time to create as you spent creating this thread.



               import mx.binding.utils.BindingUtils;
               import spark.components.Button;
               import spark.components.Image;
               public class MyButton extends Button
                    public function MyButton()
                    public var imageDisplay:Image;
                    public var icon:Object;
                    override protected function partAdded(partName:String, instance:Object):void
                         super.partAdded(partName, instance);
                         if(instance == this.imageDisplay)
                              BindingUtils.bindProperty(this.imageDisplay, "source", this, "icon");



          Now just assign "imageDisplay" to the id of the image in your skin and your done.


          That wasn't so much work now, was it?

          • 2. Re: Modify skin components at runtime
            Teriath Level 1

            Sweet, thanks.