Changing Color Through ActionScript
In this tutorials you will learn how to change a MCs (movie clip) color through actionscript. I am using flash 8, but flash MX 2004 will work fine as well.
Start off by making a new flash document and make a circle on the stage. Make sure it is a solid color, without an outline. Mine is read. Select and hit F8 to convert it to a movie clip.
Once you have done that, give the MC an instance name of ‘colorful’. (Without the quotation marks
)
Now apply this code to the first frame:
var color:Color = new Color("colorful");
color.setRGB(0×00FF00);
}
Now if you test your movie (Ctrl/Cmd+Enter), the MC should be green instead of red (This wouldn’t of worked if you had of had your MC green in the first place). Now to explain the code.
The first line, as always, means everytime the frame is entered.
The next line is making a new color object, and its target is the MC ‘colorful’.
The next line sets the color of the color object to 00FF00, which is green. If you want to find the value for a color, click on the color changer to the left of the screen. When your mouse is over a color it will display that color. (setRGB(0xRRGGBB)).
Red: FF0000, Blue: 0000FF, Green: 00FF00, White: FFFFFF, Black: 000000, Purple-Violety: B90DF2
Now what if you wanted to change the color on a key press or something? Paste this code onto the frame.
var color:Color = new Color("colorful");
if(Key.isDown(Key.SPACE)){
color.setRGB(0×00FF00);
}else{
color.setRGB(0×0000FF);
}
}
I don’t really think there is any need to explain that code, since it is practically the same as the last one.
Now if you test your movie you will get something like this:
Hit the spacebar to see the color change.















thanks a lot awesty
Thanks thats really useful
It Always Says:
**Error** Scene=Scene 1, layer=Layer 3, frame=1:Line 2: ‘)’ or ‘,’ expected
color.setRGB(0×FF0000)
Total ActionScript Errors: 1 Reported Errors: 1
Delete the 0x then retype it again in flash.
Im just testing this ok.
Dont reply to this comment delete it or let it stay
Nice tutorial, simple and easy to follow