all groups > flash actionscript > january 2005 >
You're in the

flash actionscript

group:

need help cleaning up repetitive code


need help cleaning up repetitive code posterboy
1/24/2005 9:55:34 PM
flash actionscript:
i have 14 buttons (see attached code). when i click on any button, i load an
external swf in the parent clip and make the _alpha=50; i want to disable all
14 buttons when the external swf is loaded, then enable them when the swf is
unloaded. am i anywhere close?

/// i'd like to use something like this....

var allButtons = new Array("tps_txt_btn", "imaging_txt_btn", "osd_txt_btn",
"bolts_txt_btn", "closeouts_txt_btn", "debris1_txt_btn", "debris2_txt_btn",
"scheduling_txt_btn", "training_txt_btn", "org1_txt_btn", "org2_txt_btn",
"recert_txt_btn", "photos_txt_btn", "cds_txt_btn");

tps_txt_btn.onRelease = function (){
_parent.recommendations_mc._alpha = 50;
_parent.tps_text.loadMovie ("tps_text.swf");
allButtons.enabled = false;
}

/// as opposed to this...

tps_txt_btn.onRelease = function (){
_parent.recommendations_mc._alpha = 50;
_parent.tps_text.loadMovie ("tps_text.swf");
tps_txt_btn.enabled = false;
imaging_txt_btn.enabled = false;
osd_txt_btn.enabled = false;
bolts_txt_btn.enabled = false;
closeouts_txt_btn.enabled = false;
debris1_txt_btn.enabled = false;
debris2_txt_btn.enabled = false;
scheduling_txt_btn.enabled = false;
training_txt_btn.enabled = false;
org1_txt_btn.enabled = false;
org2_txt_btn.enabled = false;
recert_txt_btn.enabled = false;
photos_txt_btn.enabled = false;
cds_txt_btn.enabled = false;
}
Re: need help cleaning up repetitive code abeall
1/24/2005 10:10:30 PM
If you stick references rather than strings in the array, ie instead of: var
allButtons = new Array('tps_txt_btn', 'imaging_txt_btn', 'osd_txt_btn', ect..)
you do: var allButtons = new Array(_root.tps_txt_btn, _root.imaging_txt_btn,
_root.osd_txt_btn, ect.) Then you could do this: for(var i in allButtons){
allButtons[ i ].enabled = false; }

buttons_arr = [_root.bttn1,_root.bttn2,_root.bttn3];

_global.changeButtons = function(prop,val){
var ar = _root.buttons_arr;
for(var i in ar){
ar[i][prop] = val;
}
}

changeButtons("enabled",false);
AddThis Social Bookmark Button