Reputation: 259
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?
Upvotes: 0
Views: 1958
Reputation: 4771
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.
Upvotes: 1
Reputation: 301
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;
Upvotes: 1
Reputation: 1031
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;
Upvotes: 0