all groups > flash actionscript > march 2005 >
You're in the

flash actionscript

group:

Color object


Color object Sumit216
3/2/2005 9:58:41 PM
flash actionscript:
I can't seem to get the bkgd color to change using this code...it works when I
put a straight value setRGB() but doesn't if I use a variable or an
array...btw...first post on here. thanks!

var bkgd_color:Color = new Color(bkgd_mc);
color = Array(["0x000000"], ["0x4CA3FF"], ["0xCA0303"], ["0x999999"],
["0xFF9900"], ["0x94FF33"], ["0x94FF33"]);

for (i=1; i<7; i++) {
this["b"+i].onPress = function() {
btn = this._name;
for (i=1; i<7; i++) {
if (btn == "b"+i) {
bcolor = color;
//bkgd_color.setRGB(0x4CA3FF);
bkgd_color.setRGB(bcolor);
}
}
};
}

Re: Color object kglad
3/2/2005 10:14:18 PM
var bkgd_color:Color = new Color(bkgd_mc);
colorA = [0x000000, 0x4CA3FF, 0xCA0303, 0x999999, 0xFF9900, 0x94FF33,
0x94FF33];
for (i=0; i<7; i++) {
this["b"+i].jvar = i;
this["b"+i].onPress = function() {
btn = this._name;
//bkgd_color.setRGB(0x4CA3FF);
bkgd_color.setRGB(colorA[this.jvar]);
};
}
Re: Color object Sumit216
3/3/2005 12:41:13 AM
Thanks kglad...for cleaning up my code and getting it to work....
I was wondering if you could clarify a line for me...this["b"+i].jvar = i;
is this a way to have a variable attached to a instance name?
like: mc1.jvar="first movieclip";
mc2.jvar="second movieclip";
if I understand it right, that's pretty cool. thanks! Sumit
Re: Color object rlc5611
3/3/2005 3:04:11 AM
Yes. It is a common mistake people make when applying button scripts in a for
loop. The button script is not actually executed until later (i.e. when you
press the button) so, at that time, 'i' could be anything but most likely will
not be what you want it to be. In fact, immediately after the for loop
terminates, 'i' would not help target any of your buttons because its value is
one more than the number of buttons you have. You have to get the value of 'i'
some way so kglad's script stores the 'i' as a persistent variable within the
instance so it can be used later. Another way to accomplish it is to extract
the number from the name on the press like:
bkgd_color.setRGB(colorA[this._name.substring(1,this._name.length)]); Also pay
attention to the fact that kglad changed your for loop to start from i=0
instead of i=1. If you start from 1, you will miss the first color in the array
because arrays are always zero-indexed.
Re: Color object kglad
3/3/2005 3:08:57 AM
Re: Color object rlc5611
3/3/2005 3:18:19 AM
Re: Color object kglad
3/3/2005 3:39:25 AM
lol. there's no need to appologize. i only get frustrated when someone posts
a message that adds confusion to the thread. and that doesn't happen very
often and never happens when one of the regulars, like you, post.
Re: Color object Sumit216
3/3/2005 5:09:36 AM
Re: Color object kglad
3/3/2005 3:52:24 PM
AddThis Social Bookmark Button