Question

I have 'i' buttons inside a MC (called "content") on my file and I cant access it using a for loop. All the buttons are in "_root.content". The code:

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]);
    }
}

Thank you!!

Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top