On 09/06/04 7:20 pm, in article ca7kdi$6cc$1@forums.macromedia.com,
[quoted text, click to view] "Larry.russell" <webforumsuser@macromedia.com> wrote:
> I am new to actionscript and I am having a bit of a problem. I have an oval
> that I would like to change color based on a variable. Such as if Variable
> s1=green the oval is green. Is there a way to do this?
>
First of all, your oval will need to be a named instance of an object
(movieclip). If it isn't already, select it on stage and choose 'Convert to
symbol' from the 'Modify' menu. Make sure you select the movieclip checkbox
in the dialogue that opens, and give the new movieclip a name.
Now you have to name the instance of that movieclip that you have on stage
(different to naming the movieclip itself). Select the movieclip instance on
the stage and enter a name for it in the <Instance Name> field of the
Property Inspector. Let's say you call it 'mcOval'.
Paste the function below into a new, empty frame in your movie.
_global.changeColor = function(obj, newcol) {
obj.myColor = new Color(obj);
obj.myColor.setRGB("0x" + newcol);
};
To use it to change the color of an object use this syntax:
changeColor(mcOval, "FF0000");
This will change the oval to red. So, if you wanted to use variables to set
the color you might write something like:
if (s1=="green") {
changeColor(mcOval, "4FAF00"); // this is the hex for a bright green
}
Hope that helps.
--
Robin Nicholl
studioalias