PDA

View Full Version : Assigning code to n buttons through actionscript


doomdrake
05-30-2008, 10:01 PM
Can you help me to assign a function to a variable number of buttons ?
I tried using the following code :

for (i=0; i<nr; i++) { this["hex"+i].onRelease = function() { //Whatever }; }

It didn't work.
The buttons are generated with the following code :

// nx = 17, ny = 10, xh = 41, yh = 36
for (i = 0; i < ny; i++)
for (j = 0; j < nx; j++)
if ((i == 0) && (j == 0))
{
}
else
{
duplicateMovieClip("tata", "umbra" + nr, nr);
setProperty("umbra"+nr, _width, 41);
setProperty("umbra"+nr, _height, 36);
setProperty("umbra" + nr, _alpha, 20);
setProperty("umbra" + nr, _x, x_curent + j * (xh - x_curent/2) );
if ((j % 2 != 0) && (i != ny))
setProperty("umbra" + nr, _y, y_curent + i*yh + y_curent);
else
setProperty("umbra" + nr, _y, y_curent + i * yh);
nr++;
}
return nr++;
}
}

Also i would ask to give me an example as to how i could assign different functions to any button. For example, function 1 to button 1, function 2 to button 2 and so on.
Please help.
:D

EDIT
Please put your code in
[ as ] [ /as ] tags (without spaces)