PDA

View Full Version : [FMX] for loops and disabling buttons



Maizoon
December 18th, 2003, 08:34 PM
So...

I have an mc that when you rollover opens a menu system. There are buttons behind this menu system that I would like to have disabled when the menu system is open and re-enabled when the menu system is closed. I have this script on my timeline:

function lnkenable(isIt) {
lnk0.enabled = isIt;
lnk1.enabled = isIt;
lnk2.enabled = isIt;
lnk3.enabled = isIt;
}

and on my menu system I have this to turn on/off the buttons:

on (rollover){
_root.lnkenable(false);
_root.menu.gotoAndPlay("open");
}
on(rollOut){
_root.lnkenable(true);
_root.menu.gotoAndPlay("closed");
}

This works as it should, however I would like to add more lnk buttons at a later date and don't want to keep adding lines of code. How can I execute this with a loop? I tried the following with no effect (the buttons behind the menu still work)

var lk;
function lnkenable(isIt) {
for (lk=0; lk<4; lk++) {
lnk[lk].enabled = isIt;
trace(lk)
trace(isIt)
}
}

I've not gotten to indepth with for loops and whatnot so I've probably butchered this. The script works when I detail each button (ie the top script) but not when I loop through them (ie the bottom script) thanks.

btw...thanks to electrongeek for the code idea

norie
December 19th, 2003, 03:14 AM
function lnkenable(isIt) {
for (i=0; i<4; i++) {
this["lnk"+i].enabled = isIt;
}
}