6 Replies Latest reply on Sep 9, 2011 7:10 AM by kglad

    Selected item : colorChangeF(mcA[i],0xFF0000);

    Ron Colmen Level 2

      If there are 10 movie clips with the same instance name (my_mc), how do I make the currently selected movieclip active (setFocus)?

       

      I want to be able to change the color of the currently selected item. The color should change when clicked on a my_mc and then click button1.

       

      Below is my color changing code and how do I do this?

       

      var mcA:Array = [_root.stars_mc.my_mc];

       

      button1.onRelease = function(){

      for (var i:Number = 0; i<mcA.length; i++) {

          colorChangeF(mcA[i],0xFF0000);

      }

      }

        • 1. Re: Selected item : colorChangeF(mcA[i],0xFF0000);
          kglad Adobe Community Professional & MVP

          never should you have more than one object with the same instance name.

           

           

          var selected_mc:MovieClip;

          for(var i:Number=0;i<mcA.length;i++){

          mcA[i].onRelease=function(){

          selected_mc=this;

          }

          }

           

           

          button1.onRelease=function(){

          if(selected_mc){

          colorChangeF(selected_mc,0xFF0000);

          }

          }

          1 person found this helpful
          • 2. Re: Selected item : colorChangeF(mcA[i],0xFF0000);
            Ron Colmen Level 2

            Thank you Keith!

             

            Sorry I've described my requirement slightly incorrectly.

             

            Here goes my exact requirement. There are 10 movieclips with the same instance name (my_mc), and in each of those movieclips there is a textfield with a instance name of 'tf'. how do I make the currently selected textfield active to change its color (setFocus)?

             

            I want to be able to change the color of the currently selected textfield. The color should change when clicked on a my_mc and then click button1. Below is my color changing code and how do I do this?

             

            I tried this though. but did not work;

             

            var selected_mc:TextField=_root.stars_mc.my_mc.tf;

            _root.stars_mc.my_mc.onRelease=function(){

            selected_mc=this;

            }

            }

             

            button1.onRelease=function(){

            if(selected_mc){

            colorChangeF(selected_mc,0xFF0000); //compilar error: Type mismatch

            }

            }

             

            function colorChangeF(mc:MovieClip, col:Number):Void {

                mc.c = new Color(mc);

                mc.c.setRGB(col);

            }

             

            Message was edited by: Ron Colmen

            • 3. Re: Selected item : colorChangeF(mcA[i],0xFF0000);
              Ron Colmen Level 2

              Sorry for the bad comminucation. Hope you'll help me out with this.

              • 4. Re: Selected item : colorChangeF(mcA[i],0xFF0000);
                kglad Adobe Community Professional & MVP

                again, never should you have more than one object with the same instance name.  if you do, and you have no other way to reference the same-named objects, you will only be able to reference (via actionscript) the last one assigned that instance name.

                 

                there are ways to work around this but they are messy and unnecessary because never should you have more than one object with the same instance name.

                1 person found this helpful
                • 5. Re: Selected item : colorChangeF(mcA[i],0xFF0000);
                  Ron Colmen Level 2

                  I understand and I have no choice here. I'm just adding this to a previosly coded fla. I'm sure I will not be able to redo the code to create those moveclips with different instance name. I need your experties in fixing this. Hope you will - Thanks Kglad.

                  • 6. Re: Selected item : colorChangeF(mcA[i],0xFF0000);
                    kglad Adobe Community Professional & MVP

                    copy and paste the code used to create those same-named movieclips.