3 Replies Latest reply on Jun 28, 2011 6:50 AM by kglad

    Using colorTrans:ColorTransform on more than one movie clip

    C_Clifft_77

      Hi I am very new to Flash and action script so please bare with me...

       

      I would like to be able to change the color of more than one movie clip in the same layer in the same frame. Basically I have place two different movie clips with defined instances,i.e. body and shoulder onto the canvas in one frame on the timeline.

       

      I have created three different buttons (red_btn, blue_btn, and yellow_btn) to use to change the color of say the body or shoulder. I would use red and blue to change the body and say yellow and green to change the shoulders. These are also on the same layer and same frame on the timeline as the movie clips.

       

      The problem I am having is how would I declare the two movies or variables to change independantly? Would I need to place one movie clip on one layer and then place the other on a different layer so that when I press the button I want i.e. the red button, it only changes the body and not the shoulders.

       

      Here is my actionscript that I am using to change the color of the clip(s)

       

      import flash.geom.ColorTransform;
      import flash.geom.Transform;

       

      var colorTrans:ColorTransform = new ColorTransform();
      var trans:Transform = new Transform(body);
      trans.colorTransform = colorTrans;

       

      blue_btn.onRelease = function() {
          colorTrans.rgb = 0x0000FF; // blue
          trans.colorTransform = colorTrans;
      };

      red_btn.onRelease = function() {
          colorTrans.rgb = 0xFF0000; // blue
          trans.colorTransform = colorTrans;
      };

      yellow_btn.onRelease = function () {
      colorTrans.rgb = 0xFFFF00; //yellow
      trans.colorTransform = colorTrans;
      }

       

      body here is my declared variable wich is the body of a shirt that is one movie clip. When you place both clips on the timeline ontop of each other, you basically get a shirt with different color shoulders and body.

       

      I need some help to know if this is possible first of all, and then what would be the best way to delcare the variables in one actionsript.

       

      Thanks and I am sorry, I just never learned much when it came to flash. Thanks for any patience and help anyone is willing to give me.

        • 1. Re: Using colorTrans:ColorTransform on more than one movie clip
          kglad Adobe Community Professional & MVP

          every movieclip has a transform.colorTransform property that you can use to assign a color transform (with any rgb property).  so, for example:

           


           

          import flash.geom.ColorTransform;
          import flash.geom.Transform;

           

          var colorTrans:ColorTransform = new ColorTransform();

           

          bluebody_btn.onRelease = function() {
              colorTrans.rgb = 0x0000FF; // blue
            yourbodymovieclip.tranform.colorTransform=colorTrans;
          };

          blueshoulders_btn.onRelease = function() {
              colorTrans.rgb = 0xFF0000; // blue
          yourshouldersmovieclip.transform.colorTransform = colorTrans;
          };

          yellowbody_btn.onRelease = function () {
          colorTrans.rgb = 0xFFFF00; //yellow
          yourbodymovieclip= colorTrans;
          }

           

          etc

           

          • 2. Re: Using colorTrans:ColorTransform on more than one movie clip
            McbainGames11 Level 2

            looks a lot harder to do it in actionscript 2.0 heres what i used  for actionscript 3.0 its much simpler and neater

            Time to change over to as3:

             


            var myColorTransform = new ColorTransform();
            var myColorTransform2 = new ColorTransform();
            var myColorTransform3 = new ColorTransform();

             

            red.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_8);

             

            function fl_MouseClickHandler_8(event:MouseEvent):void
            {
               
                my_channel = my_sound.play();
                myColorTransform.color = 0xFF0000;
                ball1.transform.colorTransform = myColorTransform;
            }

             

             

             


            pink.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_9);

             

            function fl_MouseClickHandler_9(event:MouseEvent):void
            {
              
                myColorTransform2.color = 0xFF00FF;
                ball1.transform.colorTransform = myColorTransform2;
               
            }

             

             

             


            green.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_10);

             

            function fl_MouseClickHandler_10(event:MouseEvent):void
            {
               
                myColorTransform3.color = 0x00FF00;
                ball1.transform.colorTransform = myColorTransform3;
                }

             

             

            Just add an extra variable up the top and keep adding colours so when "pink" instance is clicked "ball1" instance will turn pink

             

            I high recommend you use as3, Hope i helped.

            • 3. Re: Using colorTrans:ColorTransform on more than one movie clip
              kglad Adobe Community Professional & MVP

              there's no difference using as2 and as3 for this except for the mouse handlers.   thanks anyway.