Dynamic buttons won't display

hiya!

just trying to have mx create some buttons for me. but i’m brain dead or something today because my code’s not working and i can’t see why. on the stage, i have a movieclip whose instance name is “myMc”:

//how many buttons
var totalbuttons = 5;

//space buttons
var baseX = 10;
var baseY = 10;
var spacer = myMc._height;

//loop to create buttons
for (var y = 1; y <= totalbuttons; y++) {
myMc = duplicateMovieClip(“button” add y, eval(“button” add y), 2000 + y);
eval(“button” add y)._x = baseX;
eval(“button” add y)._y = baseY + (y - 1 * spacer);
}

shouldn’t this give me 5 buttons, nicely spaced, named button 1 thru 5? what am i missing here?

tia,

f

Hey Fortune,

Your prob is that you’re mixing Flash 4 syntax and Flash MX syntax, and that you’re doing something wrong in your duplication:

//how many buttons
var totalbuttons = 5;

//space buttons
var baseX = 10;
var baseY = 10;
var spacer = myMc._height;

//loop to create buttons
for (var y = 1; y <= totalbuttons; y++) {
	myMc = duplicateMovieClip("button", "button"+y, 2000 + y);
	myMc._x = baseX;
	myMc._y = baseY + (y - 1 * spacer);
}

if your button name is button. And when you say button, you mean button, or you mean movie clip that behaves like a button?

pom :cowboy:

hiya p!

yeah, i gotta learn the new mx coding style - in flash 5 you could basically code like flash 4, but in mx this isn’t going to work anymore! :slight_smile:

so now i have real mx code for my movie clip that will serve as a button:

//how many buttons
totalButtons = 5;

//space buttons
baseX = 0;
baseY = 0;

spacer = myMc._height + 10;

//loop to create buttons
for (y = 1; y <= totalButtons; y++) {
duplicateMovieClip (“myMc”, “button” + y, 2000 + y);
this[“button” + y]._x = baseX;
this[“button” + y]._y = baseY + ((y - 1) * spacer);
}

//clear sample clip from stage
myMc.unloadMovie();

this works. now i want to dynamically load the labels too. my movie clip has a text field, instance name “text.” i guess i want to actually want to make the variable name dynamic as well so i can set the labels in the code. something like:

but1 = news;
but2 = search;
but3 = home;
but4 = jobs;
but5 = contact;

what should i put in the variable box for the button variable so that it will pick up the label?

and to the create button code i guess i want to add a line like:

//label buttons
this[“but” + y].text = news; etc.

any hints or tips deeply appreciated!

tia,

f

First you need to store the labels in an array

labels=["news","search","home"...];

Then give your textbox the instance name myText, it’s better. And then in the loop

this["button" + y].myText.text=labels[y-1];

pom :bandit: