I'm trying to achieve a function that inserts a list of buttons on the stage. The number of the buttons should be determined by a for-loop. This is my code today. As you can see it only returns the result in a text field.
Code:
for (var i = 0; i < menuarray.length; i++)
{
xmlbox.text =xmlbox.text+"\n"+this.firstChild.childNodes[9].childNodes[i].attributes.name;
}
Just the clarify: the code I would like some help with should look something like this:
Code:
for (var i = 0; i < menuarray.length; i++)
{
insert button, x-cord = 123 and y-cord=456
}
I guess there are some nice guide out there, but I can't really find what I am looking for when searching.
I'm not asking you to do the work for me, but I would be so very thankful if someone could just point me in the right direction.
You can use an array to store the links along with a variable associated with each of the buttons.
code:
var links:Array = new Array('http://www.google.com/', 'http://www.yahoo.com/','http://www.flashkit.com/','http://www.adobe.com/','http://www.google3.com/','http://www.google3.com/','http://www.google4.com/');
for (var i = 0; i < 7; i++) {
var btn = new MyBtn();
btn.x=0;
btn.y=0+i*40;
btn.txtBox.text=i;
btn.addEventListener(MouseEvent.CLICK, myButtonFunction);
btn.i = i; // store a variable in each movie clip
addChild(btn);
}
function myButtonFunction(event: MouseEvent) {
var btn:MovieClip = MovieClip(event.currentTarget);
trace (btn.i);
var link:String = links[btn.i]; // grab the variable stored in the movie clip
trace (link);
/* uncomment this
var request:URLRequest=new URLRequest(link);
navigateToURL(request);
*/
}