: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;
system
June 17, 2004, 3:28pm
2
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:
system
June 17, 2004, 3:33pm
3
lunatic:
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
[size=1]
and happy birthday again lunatic :)[/size][font=Courier New] [/font]
system
June 17, 2004, 3:35pm
4
:trout: :smacks self with wet dead fish: D’oh! Thanks for catching that Master64!
system
June 17, 2004, 5:19pm
5
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:
system
June 17, 2004, 5:40pm
6
Yes, but what if you’ve got buttons that you don’t want it applied to ?
system
June 17, 2004, 5:42pm
7
That’s what I was thinking since the button numbers listed weren’t consecutive . . .
system
June 18, 2004, 7:54am
8
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
system
June 18, 2004, 8:10am
9
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(-:
system
June 18, 2004, 8:22am
10
[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
[size=1]
and happy birthday again lunatic :)[/size][font=Courier New] [/font]
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
Spot the difference :ne:
system
June 18, 2004, 8:30am
11
scotty:
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(-:
Yep that way will be useful cause I will need to apply to more buttons and it saves me keeping count
Im guessing its probably obvious… but do I then need to declare “length” and if so where.
system
June 18, 2004, 8:58am
12
Nope, just add the buttons to your array and Flash will "read " the “length”
scotty(-:
system
June 18, 2004, 9:47am
15
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]