PDA

View Full Version : for LOOP not working


jargon
02-25-2007, 01:26 AM
I am having some difficulty with this piece of code.. I wanted to create an array of the instance names for my buttons and only have to create the function 1 time...

menuLoc = new Array('menu_main', 'menu_philosophy', 'menu_portfolio', 'menu_resume', 'menu_contact');
for(i=0; i < menuLoc.length; i++){
_level0.navMenu.menuLoc[i].onRelease = function() {
trace(hit);
}
}

It does not give me any errors, and when I test the movie, it does not work.

Flash Gordon
02-25-2007, 01:55 AM
if they are movieclip in the array you are inputting them as strings.

plus you want trace("hit");

jargon
02-25-2007, 02:06 AM
your right... I tried the following as well but that does not work either.

menuLoc = new Array("menu_main", "menu_philosophy", "menu_portfolio", "menu_resume", "menu_contact");
for(i=0; i < menuLoc.length; ++i){
_level0.navMenu.menuLoc[i].onRelease = function() {
trace("hit");
}
}

I am supposed to list the instance name of the movie clip in the array correct?

jargon
02-25-2007, 02:37 AM
I used the following code, and it solved the problem. I did not add the hard brackets around the array.


menuLoc = new Array("menu_main", "menu_philosophy", "menu_portfolio", "menu_resume", "menu_contact");
for (i = 0; i < menuLoc.length; ++i) {
_level0.navMenu[menuLoc[i]].onRelease = function() {
trace("hit");
};
}



Thanks for the help:)

Flash Gordon
02-25-2007, 04:14 AM
menuLoc = new Array(menu_main, menu_philosophy, etc