PDA

View Full Version : how to target a movieclip whose name stored in variable



showriter4
October 8th, 2008, 10:17 PM
Hey guys,

I have what is probably a fairly easy issue. I'm trying to color movie clips, but since i'm coloring more than one movie clip, it's looping through them all and passing the movie clip instance name that needs to be colored in a variable. Flash is trying to read the variable name as the movie clip instance name in the function, not interpreting it as a variable. is there some syntax to let Flash know it's a variable name that the value needs to be read and interpreted? see below:
function colorDarkBlue(postal:String):void {
trace(postal);
var stateToShade:String = postal + "_mc";
var colorTransform:ColorTransform = this.us_map.stateToShade.transform.colorTransform;
colorTransform.color = 0x003399;
this.us_map.stateToShade.transform.colorTransform = colorTransform;
trace("color it dark blue");
}
function colorDarkBlue(postal:String):void {
trace(postal);
var stateToShade:String = postal + "_mc";
var colorTransform:ColorTransform = this.us_map.stateToShade.transform.colorTransform;
colorTransform.color = 0x003399;
this.us_map.stateToShade.transform.colorTransform = colorTransform;
trace("color it dark blue");
}and sorry about the messiness....

-Stephanie

megalord
October 9th, 2008, 09:37 AM
I had a very similar problem that I solved this way:

Lets say you have a variable MovieClipName:
var MovieClipName:String;

In this Variable you store the name of a movieClip:
MovieClipName="thename"; (or any other name you want)

Now you want to use that Variable to play the movieClip:
this[MovieClipName].play();

Notice that there is no dot (.) after "this".

This should fix your problem.

ventoline
October 9th, 2008, 11:22 AM
Hi,

I'm not a very good coder but I stumbled on something that looks like:

var theSelectedString:String;
theSelectedString as MovieClip ...


Hope this helps..