2 Replies Latest reply on Jan 21, 2011 9:32 AM by Kwangle

    Changing the Colour of Multiple Objects

    Kwangle Level 1

      Hi All,


      I have written code that continually adjusts the colour of a targetted movie clip using a Color object called 'myColor' and an Object called 'colTransform' to adjust the colour of a movie called 'myClip':


      //creates colour object and links it to movie

      myColor = new Color(myClip);

      //creates object that dictates colour adjustment

      colTransform = new Object();

      //adjusts object

      colTransform.ra = 60;

      colTransform.ga = 80;

      colTransform.ba = 100;

      colTransform.rb = 0;

      colTransform.gb = 105;

      colTransform.bb = 255;

      //applies colour values of colTransform to colour object



      This works fine but I now want to set a number of movies to the same values. Is there a way to set a colour object to more than one movie? My tests indicate that a colour object can only be set to one movie at a time, although it can be reset to another movie clip and the colour transformation re-applied to the second object:


      myColor = new Color(myClip1);


      //resets colour object to second clip

      myColor = new Color(myClip2);



      I could also write a loop that loops through a number of objects and applies the colour changes to each in turn but I'm looking for a simpler solution - is there a way of doing this?

        • 1. Re: Changing the Colour of Multiple Objects
          kglad-zqbLf4 Level 3

          you could make all the objects, you want to simultaneously color, children of the same parent and apply a color change to the parent.


          p.s.  you have a typo in your code:  myColor is not myColour

          • 2. Re: Changing the Colour of Multiple Objects
            Kwangle Level 1

            Hi - thanks for the reply,


            Yeah the text was just typed up quick to illustrate my point. I made the movies the children of a new movie clip and targeted the parent as suggested which worked very well. I did want to avoid that method initially as the position of the movies on their timeline was animated by a script but I set up the new parent movie clip to have the same origin point as the timeline on which it resides, so I was able to target the movie clips inside the new parent object  with only slightly modified code:






            movie1._x += 10;

            movie2._x += 10;




            parentMovie. movie1._x += 10;

            parentMovie. movie2._x += 10;


            Obviously I then set the colour object to link to the parent object which could then have its colour adjusted, changing all the child movie clips it contains.


            Much neater than looping through multiple instances!