Mx or flash GURU, slacker, AS KING, anybody, a little "COLOR" in your life...!?!

Hey folks, just a question about colors. Some guy a while back asking about background color struck me off to experiment… I’m having trouble, ofcourse…

See if the code is legal…

myColor = new Color(MC);//MC is a movie clip instance
Time = new Date();
Hours = Time.getHours();
if (Hours="1") {
	myColor.setRGB(0x000066);
} else if (Hours="2") {
	myColor.setRGB(0x003366);
} else if (Hours="3") {
	myColor.setRGB(0x000099);
} else if (Hours="4") {
	myColor.setRGB(0x003399);
} else if (Hours="5") {
	myColor.setRGB(0x0033cc);
} else if (Hours="6") {
	myColor.setRGB(0x0000ff);
} else if (Hours="7") {
	myColor.setRGB(0x0033ff);
} else if (Hours="8") {
	myColor.setRGB(0x0066ff);
} else if (Hours="9") {
	myColor.setRGB(0x0099ff);
} else if (Hours="10") {
	myColor.setRGB(0x00ccff);
} else if (Hours="11") {
	myColor.setRGB(0x00ffff);
} else if (Hours="12") {
	myColor.setRGB(0x00ffcc);
} else if (Hours="13") {
	myColor.setRGB(0x00ff99);
} else if (Hours="14") {
	myColor.setRGB(0x00ff66);
} else if (Hours="15") {
	myColor.setRGB(0x00ff33);
} else if (Hours="16") {
	myColor.setRGB(0x00ff00);
} else if (Hours="17") {
	myColor.setRGB(0x00cc33);
} else if (Hours="18") {
	myColor.setRGB(0x009966);
} else if (Hours="19") {
	myColor.setRGB(0x006666);
} else if (Hours="20") {
	myColor.setRGB(0x003366);
} else if (Hours="21") {
	myColor.setRGB(0x003333);
} else if (Hours="22") {
	myColor.setRGB(0x000033);
} else if (Hours="23") {
	myColor.setRGB(0xCCCCCC);
} else if (Hours="24") {
	myColor.setRGB(0xCCCCCC);
}

i would use an array to store the colors and then do something like:

myColor.setRGB(nColor[Hours]);

nColor being the name of the array and Hours being your time variable…It would get rid of all of those if/else statements…

Well, I’v never used an array, and the AS dictionary doesn’t help much, but is this the right format???

nColor = new Array();
myArray[0] = "0x000066;"
//and so on

ok how is this? Remember, its my first array, ever…

myColor = new Color(MC);
Time = new Date();
Hours = Time.getHours();
myColor.setRGB(nColor[Hours]);
//
nColor = new Array();
nColor[0] = "0x000066;";
nColor[1] = "0x003366";
nColor[2] = "0x000099";
nColor[3] = "0x003399";
nColor[4] = "0x003399";
nColor[5] = "0x0000cc";
nColor[6] = "0x0033cc";
nColor[7] = "0x0000ff";
nColor[8] = "0x0033ff";
nColor[9] = "0x0066ff";
nColor[10] = "0x0099ff";
nColor[11] = "0x00ccff";
nColor[12] = "0x00ffff";
nColor[13] = "0x00ffcc";
nColor[14] = "0x00ff99";
nColor[15] = "0x00ff66";
nColor[16] = "0x00ff33";
nColor[17] = "0x00ff00";
nColor[18] = "0x00cc33";
nColor[19] = "0x009966";
nColor[20] = "0x006666";
nColor[21] = "0x003366";
nColor[22] = "0x003333";
nColor[23] = "0x000033";

::edit:: oops i spotted an error myself, a big one lol. Ok, I fixed it. Waddya think?::/::

nColor = new Array();
nColor[0] = 0x000066;
nColor[1] = 0x003366;
nColor[2] = 0x000099;
nColor[3] = 0x003399;
nColor[4] = 0x003399;
nColor[5] = 0x0000cc;
nColor[6] = 0x0033cc;
nColor[7] = 0x0000ff;
nColor[8] = 0x0033ff;
nColor[9] = 0x0066ff;
nColor[10] = 0x0099ff;
nColor[11] = 0x00ccff;
nColor[12] = 0x00ffff;
nColor[13] = 0x00ffcc;
nColor[14] = 0x00ff99;
nColor[15] = 0x00ff66;
nColor[16] = 0x00ff33;
nColor[17] = 0x00ff00;
nColor[18] = 0x00cc33;
nColor[19] = 0x009966;
nColor[20] = 0x006666;
nColor[21] = 0x003366;
nColor[22] = 0x003333;
nColor[23] = 0x000033;
Time = new Date();
myHour = Time.getHours();
myColor = new Color(_root.MC);
myColor.setRGB(nColor[myHour]);

I think they both work…

Lost’s is easier to understand, though.

[swf=“http://www.geocities.com/h4xx02/color3.swf height=100 width=300”][/swf]

Here is a product… Come back on the hour, and the color should change a little bit… :slight_smile: Hope it works, have fun!
P.S. Thanks to <img src=“http://8ballcreations.com/lostinbeta/images/lostinbetasmiley.gif”> Lost for a tad of help :slight_smile:

well, a tad more than a tad lol.

You could also do this and only write nColor twice:

nColor = new Array()
nColor = [“0x000066”,“0x003399”, etc etc etc]

Or once:

nColor = ["0x000066","0x003399",...]; 

pom :crazy:

I don’t know why, but I like to define it as a new Array.

Makes me feel smart or stupid or something…not sure.

:P:P:P:P:P:P

Yeah, I knew you could do that…

But for editing by time… I think it would be a lot easier to edit if you do it the original way I did it.

In case you need to change the colors, that way you don’t have to sit there and count each out until you get to where you want.

For the record… I do it Ilyas’ way usually.

myArray = [0,1,2,3,4,5,6,7,8,9]

LiB: For the record :stuck_out_tongue:

lol, I always define my variable as a new Array, helps me to remember while cruising through my code…

I was saying anything about your method Jubba. If it works, use it. I was just stating that I don’t usually define my arrays the way I did for the code for morse.

Ok I always have trouble with this, so if someone can help me out I’d appreciate it. If you don’t think this is appopriate to your thread, Morse, just say so and I’ll start a new one.

You guys are saying that you can declare an array and populate it simply by saying:

myArray = [a, b, c, d];

My question is, are square brackets used only in arrays? In other words, using the square brackets automatically states that myArray is a new Array() object?

Also, does anybody know if Flash lets you name your array elements? I forget what the term for this is (referential array? damn, can’t remember), but it’s when instead of referencing an array element like myArray[6], you can say myArray[“age”] and that element would have the age of a person, for example.

-Al

Yes I do believe square brackets define arrays.

What I am wondering about that is if things like _root[“ball”+i] constitutes as an array though… not sure.

As for targeting a specific spot… Try something like this…

myArray = [];
myArray[0] = {realName:"Shane", age:"18", forumName:"Lostinbeta"};
trace(myArray[0].realName);
trace(myArray[0].forumName);
trace(myArray[0].age);

Note: The array is purposely out of order of the trace so you can see it doesn’t just go in order.

Also Note: Don’t blame me if the code doesn’t work, it is untested.

Well yeah, _root[“blabla”] constitutes an array, an array that contains everything that’s in your _root.

And I think you’re talking about associative arrays, Al: http://www.kirupaforum.com/showthread.php?s=&threadid=313

pom :crazy:

Ah, that is some cool stuff in that thread :slight_smile:

Thanks for that link Ilyas.

Thank you Ilyas, that’s the stuff. :slight_smile:

_root[“movie”+i] acts as a pointer I think. But then again, I think I read somewhere that arrays ARE pointers.