8 Replies Latest reply on Sep 20, 2011 12:50 PM by Ron Colmen

    (mgB+[j][k])

    Ron Colmen Level 2

      How can loop mcB1, mcB2, mcB3 in this same script?

       

      var mgBW:Array = [_root.CN1.text, _root.CN2.text, _root.CN3.text, _root.CN4.text]

       

      var mcB1:Array = [_root.A8, _root.B8, _root.C8, _root.D8, _root.E8, _root.F8];

      var mcB2:Array = [_root.ab1, _rootab2, _rootab3, _rootab4, _rootab, _rootab6];

      var mcB3:Array = [_root.xy4, _root.xy8, _root.xy4, _root.xy3, _root.x1, _root.y2];

       

      for (k=0; k<mgBW.length; k++) {

          for (var j:Number=1; j<11; j++){

          mgB[k].kvar=k;

          colorchange = new Color(mgB+[j][k]);{

      ///continues....

        • 1. Re: (mgB+[j][k])
          Ned Murphy Adobe Community Professional & MVP

          What do you mean?  Where are you trying to do this in the code you show... nothing indicates where you might be intending to do so.

          • 2. Re: (mgB+[j][k])
            Ron Colmen Level 2

            The names (GRAPES, APPLE, ORANGE, etc...) are being loaded from a db. All I want to do is display a color depending on the name.

            E.g. if _root.CN1.text = ORANGE : show _root.A8, _root.ab1, _root.xy4 movieclips in FF6600.

             

             

            var mgBW:Array = [_root.CN1.text, _root.CN2.text, _root.CN3.text, _root.CN4.text]

             

            var mcB1:Array = [_root.A8, _root.B8, _root.C8, _root.D8, _root.E8, _root.F8];

            var mcB2:Array = [_root.ab1, _rootab2, _rootab3, _rootab4, _rootab, _rootab6];

            var mcB3:Array = [_root.xy4, _root.xy8, _root.xy4, _root.xy3, _root.x1, _root.y2];

             

            for (k=0; k<mgBW.length; k++) {

                for (var j:Number=1; j<11; j++){

                mgB[k].kvar=k;

                colorchange = new Color(mgB+[j][k]);{

                    if (mgBW[k]== "GRAPES"){

                        colorchange.setRGB(0x000000);

                        }

            if (mgBW[k]== "APPLE"){

            colorchange.setRGB(0xFFFFFF);

            }

            if (mgBW[k]== "ORANGE"){

            colorchange.setRGB(0xFF6600);

            }

            • 3. Re: (mgB+[j][k])
              Ned Murphy Adobe Community Professional & MVP

              I still don't see, and you haven't explained, how mcB1-3 fit into the coding scheme.  I would expect to see at least something that tries to utilize the numbers 1,2,3 somewhere, but there's nothing.

              • 4. Re: (mgB+[j][k])
                Ron Colmen Level 2

                I'm not sure if this is what you are epecting, but here goes. For illustrative purpose and to keep down the number of lines I've mentioned mcB1-3, but in my final fla I'll be using mcB1-11

                 

                for (var j:Number=1; j<11; j++){

                 

                ------------------

                 

                This is where I'm trying to look which movieclips needs to change it s colour to the relevent mgBW{k}.

                 

                colorchange = new Color(mgB+[j][k]);{

                 

                ------------------

                 

                mcB1-3 : these are the movieclips waiting to change its colour depending on the furit name. The 1st mgBW will change the color of mgB1, mgB2 and mgB3's first item, The 2nd mgBW will change the color of mgB1, mgB2 and mgB3's second item,

                • 5. Re: (mgB+[j][k])
                  Ned Murphy Adobe Community Professional & MVP

                  You are not helping much with your explanations, especially when the numbers and what you try to show/say don't line up.  The following is the best I can suggest for a portion of your code from what you've offered so far

                   

                  if (mgBW[k]== "ORANGE"){

                      show this["mcB"+j][?] movieclips in FF6600

                  }

                   

                  I would have used k where I show ? except the possible values of k (mcBW.length) and the number of elements in the mcB# arrays don't agree (4 versus 6)

                  1 person found this helpful
                  • 6. Re: (mgB+[j][k])
                    Ron Colmen Level 2

                    Thanks Ned.

                     

                    Ok I see why you are confused. Have a look at this;

                     

                    var mgBW:Array = [_root.CN1.text, _root.CN2.text, _root.CN3.text, _root.CN4.text]

                     

                    var mcB1:Array = [_root.A8, _root.B8, _root.C8, _root.D8];

                    var mcB2:Array = [_root.ab1, _rootab2, _rootab3, _rootab4];

                    var mcB3:Array = [_root.xy4, _root.xy8, _root.xy4, _root.xy3];

                     

                    for (k=0; k<mgBW.length; k++) {

                        for (var j:Number=1; j<4; j++){

                        (["mcB"+j][k]).kvar=k;

                        colorchange = new Color(["mcB"+j][k]);{

                            if (mgBW[k]== "GRAPES"){

                                colorchange.setRGB(0x000000);

                                }

                    if (mgBW[k]== "APPLE"){

                    colorchange.setRGB(0xFFFFFF);

                    }

                    if (mgBW[k]== "ORANGE"){

                    colorchange.setRGB(0xFF6600);

                    }

                     

                    //I want to achieve

                    //E.g. if _root.CN1.text = ORANGE : show _root.A8, _root.ab1, _root.xy4 movieclips in FF6600.

                    //the above code doesn't work.

                    • 7. Re: (mgB+[j][k])
                      Ned Murphy Adobe Community Professional & MVP

                      It will be even better if you can figure out why you are confused.

                       

                      The following line is incorrect.  When you use bracket notation, you need to provide a parent reference ahead of the brackets...

                       

                      (["mcB"+j][k]).kvar=k;

                       

                      should maybe be....

                       

                      this["mcB"+j][k].kvar = k;

                       

                      assuming whatever object is represented by that can be assigned a kvar property.

                       

                      First get that part right in that line and the one that follows it, then try to reason out wha else you need to do.

                      • 8. Re: (mgB+[j][k])
                        Ron Colmen Level 2

                        Thank you Ned! I believe this would fix it. I'll try this shortly and mark the thread as 'Correct Answer'