Skip to main content
Inspiring
May 21, 2013
Answered

entry level array question

  • May 21, 2013
  • 1 reply
  • 513 views

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.

This topic has been closed for replies.
Correct answer teeronline

oh I got it,

var newColor = this.colorCC;

1 reply

Inspiring
May 21, 2013

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;  <<icolor is mc on stage

    trace(names);          << this trace is good

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

}


Inspiring
May 21, 2013

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;

    trace(colorCode);  

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

    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

    }

}

teeronlineAuthorCorrect answer
Inspiring
May 22, 2013

oh I got it,

var newColor = this.colorCC;