Actionscript 在循环期间在getUrl中使用连接?

Actionscript 在循环期间在getUrl中使用连接?,actionscript,concatenation,Actionscript,Concatenation,我想编写包含“getURL”的Actionscript循环。然而,从我所看到的getURL不允许变量名的串联 我有变量textholder0、textholder1、textholder2,它们的值是movieclip名称,而link0、link1、link2的值是网址 我可以使用这个[“textholder”+0].onRelease但是getURL(“link”+0)给出了“undefined” 有什么方法可以做到这一点,这样我就可以为上面的内容创建一个循环 这是一个测试。不幸的是,它仍然

我想编写包含“getURL”的Actionscript循环。然而,从我所看到的getURL不允许变量名的串联

我有变量textholder0、textholder1、textholder2,它们的值是movieclip名称,而link0、link1、link2的值是网址

我可以使用这个[“textholder”+0].onRelease但是getURL(“link”+0)给出了“undefined”

有什么方法可以做到这一点,这样我就可以为上面的内容创建一个循环


这是一个测试。不幸的是,它仍然为URL提供“undefined/”。为了简单起见,我创建了三个电影剪辑,分别是textholder0、textholder1和textholder2。在主时间线上放置一个循环

var links:Array = ["http://www.google.ca", "http://www.google.com", "http://www.google.ru"];

for(var i:Number=0; i<links.length; i++){
    this["textholder" + i].linkURL = links[i];
    this["textholder" + i].onRelease = function() { 
        getURL(linkURL); 
    }    
}
我开始认为您根本不能在循环中使用onRelease

getURL(“link”+0)
将尝试转到URL“link0”,因为
“link”+0
将连接到字符串“link0”,而不会获取
link0
的值。但您可以尝试这样做:

getURL(this["link" + 0]);

括号表示法的区别和机制在于,可以通过两种方式引用对象的属性-使用点表示法,如this.link0,或括号表示法,如this[“link0”]。但是它必须表示为一个对象属性,只要在任何地方说
“link”+0
,就像在
getURL(“link”+0)
中一样,它不会引用
link0

ok,所以我认为这里的循环的问题是,它在单击任何按钮之前递增了“I”变量

Seniocul.com说“您需要定义一个新的、唯一的变量来表示函数创建时的值,并让函数引用该值”

所以循环如下

var links:Array = ["http://www.google.ca", "http://www.google.com", "http://www.google.ru"];

var curr_button;

for(var i=0; i<=links.length; i++){
    curr_button = this["textholder"+i];
    //note creation of an extra variable "num" below to store the temp number 
    curr_button.num = i;
    curr_button.onRelease = function() { 
        getURL(links[this.num]); 
    }    
}
var链接:数组=[”http://www.google.ca", "http://www.google.com", "http://www.google.ru"];
var curr_按钮;

对于(var i=0;iby使用getURL上方的行(this[“link”+0]),我得到“undefined”
getURL(this["link" + 0]);
var links:Array = ["http://www.google.ca", "http://www.google.com", "http://www.google.ru"];

var curr_button;

for(var i=0; i<=links.length; i++){
    curr_button = this["textholder"+i];
    //note creation of an extra variable "num" below to store the temp number 
    curr_button.num = i;
    curr_button.onRelease = function() { 
        getURL(links[this.num]); 
    }    
}