PDA

View Full Version : Creating buttons with a loop and array


Althalas
03-21-2006, 07:18 PM
Right, here's the problem:

I am trying to create first an array of buttons(with pure actionscript), followed by drawing and moving each button into position according to a loop. For example, 10 buttons at coordinates (20*i,20*i) when i goes from 1 to 10.

What I have currently is the following abomination unto nature:

//Create an array and trace the label of the first one (returns undefined)
mx.accessibility.ButtonAccImpl.enableAccessibility ();
import mx.controls.Button;
var buttonArray:Array = Array();
for(i=0;i<10;i++){
buttonArray[i] = new Button("my_button"+i,10,{label:i});
}
trace(buttonArray[0].label);

If I get this fixed I guess the next step would be actually creating the set of 10 buttons. For this, I was thinking along the lines of:

//create the buttons
for(i=0;i<10;i++){
createClassObject(this,buttonArray[i]);
buttonArray[i].move(20*i,20*i)
}

There it is. Anyone?

*braces for impact*

Althalas
03-27-2006, 06:05 AM
92 views and no replies? If this is not a simple question and I'm in the wrong part of the forums, please tell me. Ditto if I left out some important information or if I'm doing it wrong on so many levels that noone can't be bothered to sort them out. It's been up almost a week now - I would truly appreciate if someone told me what I am doing wrong.