Simplify this ;-)

:jail: Hi all,

Just wrote the following code and was wondering what the syntax would be to write it shorter.

Would really appreciate your help since im a bit pushed for time at the moment…

Cheers,

Claire

_root.scroll.btn1._alpha = 30;
_root.scroll.btn1.enabled = false;

_root.scroll.btn39._alpha = 30;
_root.scroll.btn39.enabled = false;

_root.scroll.btn7._alpha = 30;
_root.scroll.btn7.enabled = false;

_root.scroll.btn40._alpha = 30;
_root.scroll.btn40.enabled = false;

Um . . … so you know anything about arrays? how about for loops?


btnArray = [btn1, btn39, btn7, btn40]
for(j=0, j<4, j++){
_root.scroll[btnArray[j]].enabled = false;
_root.scroll[btnArray[j]]._alpha = 30;
}

should work :ne:


   [font=Courier New] btnArray = ["btn1", "btn39", "btn7", "btn40"]
   for(j=0, j<4, j++){
   _root.scroll[btnArray[j]].enabled = false;
   _root.scroll[btnArray[j]]._alpha = 30;
   }
   

[/font]in “”
now it will work :stuck_out_tongue:
[size=1]
and happy birthday again lunatic :)[/size][font=Courier New] [/font]

:trout: :smacks self with wet dead fish: D’oh! Thanks for catching that Master64! :stuck_out_tongue:

And another way, where there is no need to even create an array to store button instance names…


for(btn in _root.scroll){
	if(_root.scroll[btn] instanceof Button){
		_root.scroll[btn]._alpha=30;
		_root.scroll[btn].enabled=false;
	}
}

This basically says for every object of the Button class at this _path (_root.scroll) set the alpha and enabled properties to 30 and false respectively.

:snug:

Yes, but what if you’ve got buttons that you don’t want it applied to ? :wink:

That’s what I was thinking since the button numbers listed weren’t consecutive . . . :slight_smile:

Thanks for the options… useful to know mindfriction and im sure will come in handy in the future…… but as Voetsjoeba & Lunatic mentioned in this instance I wanted to apply only to a selection of the mc’s.

Cheers,

Claire

Just an idea

btn_array = new Array();
btn_array = ["btn1", "btn7", "btn39", "btn40"];
for (i=0; i<btn_array.length; i++) {
	_root.scroll[btn_array*].enabled = 0;
	_root.scroll[btn_array*]._alpha = 30;
}

scotty(-:

To eliminate the two syntax errors:

btnArray = [“btn1”, “btn39”, “btn7”, “btn40”]
for(j=0; j<4; j++) {
_root.scroll[btnArray[j]].enabled = false;
_root.scroll[btnArray[j]]._alpha = 30;

}

Don’t let it be said that im not making progress :wink:
Spot the difference :ne:

Yep that way will be useful cause I will need to apply to more buttons and it saves me keeping count :wink:

Im guessing its probably obvious… but do I then need to declare “length” and if so where.

Nope, just add the buttons to your array and Flash will "read " the “length”:wink:

scotty(-:

fantastic!!

welcome!!

you all need help

[AS]
function setAE(b_btn)
{
b_btn._alpha = 30;
b_btn.enabled = false;
}

setAE(_root.scroll.btn1);
setAE(_root.scroll.btn7);
setAE(_root.scroll.btn39);
setAE(_root.scroll.btn40);
[/AS]