「getURL」を含む Actionscript ループを書きたいと思います。しかし、私が見ることができることから、getURL は変数名の連結を許可していませんか?
ムービークリップ名を値として持つ変数 textholder0、textholder1、textholder2 と、Web サイトのアドレスを値として持つ link0、link1、link2 があります。
this["textholder" + 0].onRelease を使用できますが、 getURL("link"+ 0) は「未定義」を返します
textholder0.onRelease = function()
{
getURL(link0);
}
textholder1.onRelease = function()
{
getURL(link1);
}
textholder2.onRelease = function()
{
getURL(link2);
}
上記のループを作成できるように、これを行う方法はありますか?
これがテストです。残念ながら、それでも URL に「undefined/」が表示されます。簡単にするために、インスタンス textholder0、textholder1、textholder2 を含む 3 つのムービー クリップを作成しました。メイン タイムラインにループを配置します。
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);
}
}
これはデバッガウィンドウからの出力です
Variable _level0.links = [object #1, class 'Array'] [
0:"http://www.google.ca",
1:"http://www.google.com",
2:"http://www.google.ru" ]
Variable _level0.i = 3
Movie Clip: Target="_level0.textholder0"
Variable _level0.textholder0.linkURL = "http://www.google.ca"
Variable _level0.textholder0.onRelease = [function 'onRelease']
Movie Clip: Target="_level0.textholder1"
Variable _level0.textholder1.linkURL = "http://www.google.com"
Variable _level0.textholder1.onRelease = [function 'onRelease']
Movie Clip: Target="_level0.textholder2"
Variable _level0.textholder2.linkURL = "http://www.google.ru"
Variable _level0.textholder2.onRelease = [function 'onRelease']
ループ内で onRelease をまったく使用できないと考え始めています。