-1

我的文件中有一个 MC 内的“i”按钮(称为“内容”),我无法使用 for 循环访问它。所有按钮都在“_root.content”中。编码:

var btns:Array = [1, 90, 180, 270, 360];

for(var i:Number = 0; i < btns.length; i++){
    var btnsName:String = "btn" + i; //instance name of buttons

    // is this okay? "content.var.etc" I havent any error but doesnt work :/
    content.btnsName.onPress = function(){
        btnPress(btns[i]);
    }
}

谢谢!!

4

1 回答 1

1
var btns:Array = [1, 90, 180, 270, 360];

for (var i:Number = 0; i < btns.length; i++)
{
    var btnsName:String = "btn" + i; //instance name of buttons

    content[btnsName].clickValue = btns[i];
    content[btnsName].onPress = function()
    {
        btnPress(this.clickValue);
    };
}

function btnPress(i)
{
    trace("Clicked Value is : " + i);
}
于 2013-11-08T18:17:33.003 回答