4 Replies Latest reply on Aug 18, 2009 10:48 PM by Ratsnackbar

    function in a custom component


      My question is, if I have a function (example: restore( )) that for example change the background color and I created 2 or more


      of the custom component.


      is there a way that if I call the function restore( ), can it change the background color of all the custom components in the application?


      if so, how can this be done?


      Thank you.

        • 1. Re: function in a custom component
          Madhav Subedi Level 4

          yes of course, if your component supports backgroundColor


          you should declare your function public, and change backgroundColor inside it.


          public function restore():void


               this.opaqueBackground = 0xFFFFFF;




          • 2. Re: function in a custom component
            alex-86 Level 1

            but dont I have to bind the function? because if I dont bind it, it wont work.


            and if i bind it,


            how can i call the function in order for all the components in the application to change their backgraund at the same time?

            • 3. Re: function in a custom component
              Madhav Subedi Level 4

              if you want to bind, then simply use property - backgroundColor to a application wise variable ( of course you should declare it bindable ), why do you need a function?


              <component backgroundColor="{componentBG}"...... // in your main page, which also consists [Bindable]private var componentBG

              • 4. Re: function in a custom component
                Ratsnackbar Level 2



                     You could create a ValueObject containing getters and setters for the variables you want to make global for all instances of the custom component.  The custom components can then bind to the value object for their properties.  Make the ValueObject a singleton and then when you make a change to one of the properties in the valueobject all instances that use it will receive the same value.  Depending on the component you may need to invalidate the display list so you may need to set up some listeners and handlers for property change events from the VO.