11 Replies Latest reply on Jul 9, 2009 10:50 AM by kglad

    Can't get this loop to work

    chester709

      I've got a matrix of image icons and I want the outline of each icon to change color on a rollover.  The number of icons in the table can vary depending on the gallery so I want to put this code in a loop.  The code I'm using is:

       

      frameColorOverVar = String("0x" + "000000");

       

      for (i = 1; i <= numberOfImages; i++) {

       

      this["frameColor"+i] = new Color(this["frameBox_inst"+i]);

      this["frameBox_inst"+i].onRollOver=function(){"frameColor"+[i].setRGB(frameColorOverVar);} ;

       

      };

       

      Where frameBox_inst1....i  are the icon boxs that I want to change color.  I've got plenty of these sorts of loops working elsewhere so I don't think it's a basic syntax problem (my I'm not certain).  I've used some traces to to work out that everything seems to be working apart from the color doesn't actually change when you roll over.  If I take it out of the look and write a statement for each icon it works perfectly.  Any ideas?

        • 1. Re: Can't get this loop to work
          Ned Murphy Adobe Community Professional & MVP

          ...."frameColor"+[i].....  in the onRollOver function doesn't look rght

          • 2. Re: Can't get this loop to work
            kglad Adobe Community Professional & MVP

            it more than doesn't look right.  it's not right.  use:

             


             

            frameColorOverVar = String("0x" + "000000");

             

             

             

            for (i = 1; i <= numberOfImages; i++) {

             

            this["frameColor"+i] = new Color(this["frameBox_inst"+i]);

            this["frameBox_inst"+i].onRollOver=function(){this["frameColor"+i].setRGB(frameColor OverVar);};

             

            };

             

             

            • 3. Re: Can't get this loop to work
              chester709 Level 1

              Thanks but I'm afraid that still doesn't work.  Same problem  - it just doesn't seem to register the color when it's put within a loop.

              • 4. Re: Can't get this loop to work
                Ned Murphy Adobe Community Professional & MVP

                I'm not color-knowledgeable when it comes to AS, so my offering are limited to what I can detect...

                 

                Is assigning the color value as a String working when you do it the way you say worked?  0x000etc are number values.  I think in AS2 allowance was made for quoting those values, but I'm pretty sure in AS3 they won't fly as strings.

                • 5. Re: Can't get this loop to work
                  kglad Adobe Community Professional & MVP

                  as2 will convert the string to a color (correctly).

                   

                  if the loop's not working it's because you have a variable or variables undefined or mis-defined (assuming you removed those spaces).

                   

                  what's the following show:

                   

                   

                   

                  frameColorOverVar = String("0x" + "000000");

                   

                   

                   

                  for (i = 1; i <= numberOfImages; i++) {

                   

                  this["frameColor"+i] = new Color(this["frameBox_inst"+i]);

                  trace(this["frameBox_inst"+i]);

                  this["frameBox_inst"+i].onRollOver=function(){this["frameColor"+i].setRGB(frameColorOverVa r);};

                   

                  };

                  • 6. Re: Can't get this loop to work
                    chester709 Level 1

                    It shows:

                     

                     

                    _level0.frameBox_inst1

                    _level0.frameBox_inst2

                    _level0.frameBox_inst3

                    .

                    .

                    .

                    _level0.frameBox_inst54

                     

                    (I've got 54 boxes)

                     

                    I think all the variables are defined.  I'm stumped but I think the problem is on this line:

                     

                    this["frameBox_inst"+i].onRollOver=function(){this["frameColor"+i].setRGB(frameC olorOverVar);};

                     

                    Because replacing it with 54 lines as follows works perfectly:

                     

                    this.frameBox_inst1.onRollOver=function(){frameColor1.setRGB(frameColorOverVar);};

                    this.frameBox_inst2.onRollOver=function(){frameColor2.setRGB(frameColorOverVar);};

                    .

                    .

                    .

                     

                    • 7. Re: Can't get this loop to work
                      kglad Adobe Community Professional & MVP

                      oops, my bad.  that should be:

                       


                       

                      frameColorOverVar = String("0x" + "000000");

                       

                       

                       

                      for (i = 1; i <= numberOfImages; i++) {

                       

                      this["frameColor"+i] = new Color(this["frameBox_inst"+i]);

                      this["frameBox_inst"+i].ivar=i;

                      this["frameBox_inst"+i].onRollOver=function(){

                      this["frameColor"+this.ivar].setRGB(frameColorOverVar);

                      };

                      };

                       

                      // or, even easier:

                       

                       

                      frameColorOverVar = String("0x" + "000000");

                       

                       

                       

                      for (i = 1; i <= numberOfImages; i++) {

                       

                      this["frameBox_inst"+i].color= new Color(this["frameBox_inst"+i]);

                      this["frameBox_inst"+i].onRollOver=function(){

                      this.color.setRGB(frameColorOverVar);

                      };

                      };

                       

                       

                      • 8. Re: Can't get this loop to work
                        chester709 Level 1

                        Would love to be reporting back it worked but I'm afraid just same old same old - no errors but no change of color on rollover!!!

                        • 9. Re: Can't get this loop to work
                          kglad Adobe Community Professional & MVP

                          the 2nd snippet should work or you have some other issue.  the first snippet should be:

                           


                           


                           

                          frameColorOverVar = String("0x" + "000000");

                           

                           

                           

                          for (i = 1; i <= numberOfImages; i++) {

                           

                          this["frameColor"+i] = new Color(this["frameBox_inst"+i]);

                          this["frameBox_inst"+i].ivar=i;

                          this["frameBox_inst"+i].onRollOver=function(){

                          this._parent["frameColor"+this.ivar].setRGB(frameColorOverVar);

                          };

                          };

                           

                          // or, even easier:

                           

                           


                          • 10. Re: Can't get this loop to work
                            chester709 Level 1

                            That worked.  Many thanks - I think you have helped me out of a hole in the past.  Really appreciated.  I'm trying hard to learn this stuff but then I come up against stuff like this that throws me!

                            • 11. Re: Can't get this loop to work
                              kglad Adobe Community Professional & MVP

                              you're welcome.