开发者

insert string info into addressing a movieclip in as3?

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?


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;


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.


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜