如何动态创建 _global 变量?像: _global.eval(“var” + i)
我很确定 eval 不会以这种方式工作,但它传达了这个想法。我正在尝试动态创建全局变量;这是我的代码:
var ti_arr:Array = new Array;
_global.a = new Object;
for (var t=0; t<group_count-1; t++) {
numOfItems = group_nodes[t].childNodes.length;
ti_arr = "tab_info" add t;
// <-- I want to define a global array with the name held in ti_arr here
for (var i=0; i<numOfItems; i++) {
eval(ti_arr)[i].a.name = tempNode.attributes.name; //<-- or give the array global scope here
eval(ti_arr)[i].a.value = tempNode.attributes.value;
}
}
我需要: tab_info1.a.name 具有全局范围。
I'm pretty sure eval doesn't work this way, but it gets the idea across. I'm trying to dynamically create global variables; here's my code:
var ti_arr:Array = new Array;
_global.a = new Object;
for (var t=0; t<group_count-1; t++) {
numOfItems = group_nodes[t].childNodes.length;
ti_arr = "tab_info" add t;
// <-- I want to define a global array with the name held in ti_arr here
for (var i=0; i<numOfItems; i++) {
eval(ti_arr)[i].a.name = tempNode.attributes.name; //<-- or give the array global scope here
eval(ti_arr)[i].a.value = tempNode.attributes.value;
}
}
I need: tab_info1.a.name to have global scope.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经脱离动作脚本循环有一段时间了:
eval 不好..括号很好。
http://www.kirupa.com/forum/showthread.php?t=259717
这里简单地解释了,不知道为什么对 eval() 进行了如此多的搜索没有让我更快地找到这个。
I've been out of the actionscript loop for a while:
eval is bad.. brackets are good.
http://www.kirupa.com/forum/showthread.php?t=259717
It's explained simply here, not sure why so much searching on eval() didn't net me this sooner.