flash as3动态实例变量名/串联
我有一个像这样的项目类型代码数组:
project_types_array[0] = "p"
project_types_array[1] = "exp"
等
以及一组相应的影片剪辑,导出为动作脚本,名称为:
type_p
type_exp
等。
我想根据存在于其中的项目类型以某种方式动态地将影片剪辑附加到舞台上大批。我可以做这样的事情:
for ( var i in project_types_array) {
if (project_types_array[i] == "p"){
var clip_p = new type_p();
container.header.type_loader.addChild(clip_p);
}
}
但我宁愿做这样的事情:
for ( var i in project_types_array) {
var "clip_" + project_types_array[i] = new "type_" + project_types_array[i]();
container.header.type_loader.addChild("clip_"+project_types_array[i]);
}
我该如何实现这一点?
I have an array of project type codes like this:
project_types_array[0] = "p"
project_types_array[1] = "exp"
etc.
and a corresponding set of movie clips, exported for actionscript, with names:
type_p
type_exp
etc.
I want to somehow dynamically attach a movieclip on the stage according to the project type that exists in the array. I could just do something like this:
for ( var i in project_types_array) {
if (project_types_array[i] == "p"){
var clip_p = new type_p();
container.header.type_loader.addChild(clip_p);
}
}
but I'd rather do something like this:
for ( var i in project_types_array) {
var "clip_" + project_types_array[i] = new "type_" + project_types_array[i]();
container.header.type_loader.addChild("clip_"+project_types_array[i]);
}
How do I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
http:// help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName%28%29
try
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName%28%29