views:

25

answers:

3

I am trying to dynamically address different instances of the same movieclip by passing a string into the movieclip address, but apparently I don't know what I'm doing. I'm trying something like below:

var vsTargetName:String;
vsTargetName = "instance50";
vsTargetName + vsThumb.thumbHighlight.visible = true;

Is something like this possible? What am I doing wrong/what do I need to do to make that work?

A: 

In AS2 you had to call the eval() to convert a string into their relative stage object. Not sure how you would do it in AS3, I'm new to it.

var myID = "someObjectID";
var myObject = eval("someParent." + myID);
myObject._visible = false;
woodscreative
+1  A: 

You could use getChildByName. For example:

var vsTargetName:String = "instance50";
//container is a parent of vsTarget
var vsTarget:MovieClip = container.getChildByName(vsTargetName);
vsTarget.thumbHighlight.visible = true;
Miha
A: 

You can interchange object notation and array notation for DisplayObjects.

So:

var vsTargetName:String = "instance50";
this["instance50"] === this.instance50 === this[vsTargetName]

Hope that helps. You can use different combinations to select what you need:

var num:String = 50;
this["instance" + num]

The code above is very useful for loops when the MovieClip names are numbered.

Sandro