3 Replies Latest reply on May 21, 2013 9:56 PM by teeronline

    entry level array question

    teeronline

      I'm new to array, I have a bunch of color codes that I want to assign to an array,

       

      #000000,

      #00008B,

      #00009C,

      #0000CD,

      #0000FF,

      #002395,

      #002E63,

      #002FA7,

      #00308F,

      #003366

       

      in AS2 I have so far

       

      var i=1;

       

      while (i<11) {

          this["icolor"+i] =

      }

       

      how do i do this within a loop, while every time 'i' imprement, it will asign the next color code on the list? I think this is pretty fundamental.. i'm still doing research on this, great if someone just point it out to me.

       

      Thanks  a lot.

        • 1. Re: entry level array question
          teeronline Level 1

          Trying to test with names first, what's the problem in my sample?

           

          var names:Array = new Array("Belinda", "Gina", "Kathy", "Charlotte", "Jane");

           

          for(i=0; i< names.length; ++i){

              var u=i+1;

              this("icolor"+i).nAme = names[i];  <<icolor is mc on stage

              trace(names[i]);          << this trace is good

              trace(this("icolor"+i).nAme );  << this trace give me undefine

          }

           

           


          • 2. Re: entry level array question
            teeronline Level 1

            so I construct it to this point. I don't know why it doesn't work

             

            var colorCode:Array = new Array("0xFFA83C", "0x333333", "0x666666", "0x999999", "0xCCCCCC");

             

            for(i=0; i< colorCode.length; ++i){

                var u=i+1;

                this["icolor"+u].colorCC = colorCode[i];

                trace(colorCode[i]);  

                trace(this["icolor"+u].colorCC ); << value the same as colorCode[i]

                this["icolor"+u].onPress = function () {

                var my_color:Color = new Color(currentObjectTarget); << to change the color of currentObjectTarget

                var newColor = this["icolor"+u].colorCC;

                my_color.setRGB(newColor);  << if I substitute newColor to just  some color code , it work

                }

            }

            • 3. Re: entry level array question
              teeronline Level 1

              oh I got it,

               

              var newColor = this.colorCC;