Skip to main content
June 10, 2006
Answered

Change Movie Clip Color with External Variable

I have a movieclip in my flash file (WhiteBarMC) that I want to be able to change colors on using a variable (hexidecimal number) assigned from an external file. I found a script that gets closer to what I want to achieve, but I'm not sure how to execute the alterations I need to make it work.

on (rollOver) {
var colorful = new Color("_root.WhiteBarMC");
colorful.setRGB(0x006699);
}

This is close because it changes my object/Movie Clip on roll over. BUT, I have two problems...

1) I want to set the hex-color code in an external file as a variable that flash retrieves and then applies to this movieclip. If it helps to explain why, it's because I have multiple variations of this swf throughout my site with different text overlaying the colored movieclip bar (i.e. galleries, contact, about, etc.) So, with one change in an external file, I have the ability to change the color bars globally to match changing color schemes on the site.

I set up an external ".txt" file with only "var myColor=CC0033" in the file. I'm not sure if that's right, or even the right method, but I thought it would help you smarter ones to know what I'm doing.

2) I don't want my viewers to have to "roll over" it to actuate the change. I want it to happen on load.


ANYONE who can help is a hero. Remember, I'm not that proficient at action script, so a little guidance and clarity in your response will help immensley! I owe you a dinner!
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
June 10, 2006
Place this code on the root timeline containing your clip:

my_lv = new LoadVars();
my_lv.onLoad = function(s){
if(s){
var colorful = new Color(_root.WhiteBarMC);
colorful.setRGB(this.myColor);
}else{
trace("Unable to load file");
}
}
my_lv.load("colors.txt");

Where colors.txt is a file with: &myColor=0xCC0033& (as kglad said)

3 replies

2m91_2
Inspiring
June 10, 2006
dinner sounds great ;-)

instead of using an external file (txt or xml) which would be a bit more complicated (as you have to know when it has finshed loading) you could try to use flashvars. That would only be a good choice though if you use your swf on only one page, or on dynamicaly created ones.

If that is the case and you need more help - let us know.

What kglad wrote about the color-variable would be right in any case. (Guess he's the one who's earned the main course, but I'll try for dessert ;-) )

if you want to use clip events your code would be:

onClipEvent (load) {
var colorful = new Color(this);
colorful.setRGB(_root.myColor);
}
put directly on the clip in question.

on a timeline frame frame it would be:

var colorful = new Color("_root.WhiteBarMC");
colorful.setRGB(_root.myColor);
Translate
kglad
Community Expert
Community Expert
June 10, 2006
1. use: &myColor=0xCC0033&

2. attach your code to frame 1 of your _level0 timeline.
Translate
Correct answer
June 10, 2006
Place this code on the root timeline containing your clip:

my_lv = new LoadVars();
my_lv.onLoad = function(s){
if(s){
var colorful = new Color(_root.WhiteBarMC);
colorful.setRGB(this.myColor);
}else{
trace("Unable to load file");
}
}
my_lv.load("colors.txt");

Where colors.txt is a file with: &myColor=0xCC0033& (as kglad said)
Translate