[FMX] need help with colour please!

I have a movie clip called “over”. I have created 4 instances named over1, over2, over3 and over4

I have 4 text fields called workscroll1 - 4

I want to set the colour of the over MC’s to white and the colour of the text fields to a colour I have created elsewhere in the site ( called menuTextStyleUp1)

Below is the code i have used and while it works ok, i have quite a few instances in the site where I am doing similar things

skinWorkAreaOver1 = new Color(_root.over1);
skinWorkAreaOver2 = new Color(_root.over2);
skinWorkAreaOver3 = new Color(_root.over3);
skinWorkAreaOver4 = new Color(_root.over4);

skinWorkAreaOver1.setRGB(_global.white); // set colour of mouse over box to no colour
skinWorkAreaOver2.setRGB(_global.white); // set colour of mouse over box to no colour
skinWorkAreaOver3.setRGB(_global.white); // set colour of mouse over box to no colour
skinWorkAreaOver4.setRGB(_global.white); // set colour of mouse over box to no colour

_root.workscroll1.setTextFormat (_root.menuTextStyleUp1); // change the colour of the text to the default colour
_root.workscroll2.setTextFormat (_root.menuTextStyleUp1); // change the colour of the text to the default colour
_root.workscroll3.setTextFormat (_root.menuTextStyleUp1); // change the colour of the text to the default colour
_root.workscroll4.setTextFormat (_root.menuTextStyleUp1); // change the colour of the text to the default colour

Could someone help me to put this into a loop.

I have looked at some of the tutorials on this site and tried the following but get errors

i = 4;
while (i > 0) {
eval(“skinWorkAreaOver” +i) = new Color(_root[“over” +i]);
eval(“skinWorkAreaOver” +i).setRGB(_global.white);
_root.workscroll1.setTextFormat _root[“menuTextStyleUp” +i]);
i–;
}

:cyclops:

try this:

for (k=1; k<=4; k++) {
	this["skinWorkAreaOver"+k] = new Color(this["over"+k]);
	this["skinWorkAreaOver"+k].setRGB(_global.white);
	this["workscroll"+k].setTextFormat(this["menuTextStyleUp"+k]);
}

:-\

thanks heaps kax

the code worked fine (fla attached) and should stop my code becoming spaghetti

are you able to tell me a bit about how the “this” works (or point me to a resource)

i have read the flash help file but am not really any wiser

redd

i think if you look in the tutorials section in actionscript, there something about ‘this’. i’ll see if i can get you the link in a sec

http://www.kirupa.com/developer/actionscript/tricks/root_parent_this.asp

i think that should explain it

there’s something i’d like to mention…

the script in a button, is referenced to the timeline, not to the button.
so if you ever use the same script in a movie clip, you’ll need to change this to _parent :wink:

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary806.html