all groups > flash actionscript > january 2006 >
You're in the

flash actionscript

group:

loops and arrays


loops and arrays rickjanusz NO[at]SPAM mac.com
1/28/2006 8:55:44 PM
flash actionscript:
HELP PLEASE

Hi all,

I am trying to set my buttons to an array and control the actions via looping
statement but am not getting it. this is my code:

var buttons:Array = new Array("btn1_btn", "btn2_btn", "btn3_btn", "btn4_btn",
"btn5_btn");
function doSomething() {
for (var i:Number = 0; i<buttons.length; i++) {
var names:String = buttons[i];
var currentButton:MovieClip = this[names]._name;
currentButton.onPress = function () {
myVariable._x = currentButton._x;
trace(currentButton);
};
}
}
doSomething();

the problem is that after I declare the looping statement and trace it, I get
all the names but once I declare the next function
I dont know how to code it so that when they press one of the buttons in the
array, it executes the code..HELP!!! PLEEZZE!!!

Thank you
Re: loops and arrays kglad
1/28/2006 9:16:06 PM
var buttons:Array = new Array("btn1_btn", "btn2_btn", "btn3_btn", "btn4_btn",
"btn5_btn");
function doSomething() {
for (var i:Number = 0; i<buttons.length; i++) {
_root].ivar = i;
_root].onPress = function() {
myVariable._x = this._x;
trace(this+" is button number "+this.ivar);
};
}
}
doSomething();
AddThis Social Bookmark Button