Hi, I have 15 buttons on Stage.
All of them are named similar except numbers (1-15)
Action Scripts are also the same except numbers (1-15).
Script is pretty long, can it be optimized using something like "for" cycle or arrays?
15_buttons.flaCode://path button 1 this.path_button_1.enabled = true; this.path_button_1.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_1.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_1.onPress = function() { character.goToNode("node_1", characterMoveCallback, false); showbtn(); hidebtn(path_button_1); }; //path button 2 this.path_button_2.enabled = true; this.path_button_2.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_2.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_2.onPress = function() { character.goToNode("node_2", characterMoveCallback, false); showbtn(); hidebtn(path_button_2); }; //path button 3 this.path_button_3.enabled = true; this.path_button_3.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_3.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_3.onPress = function() { character.goToNode("node_3", characterMoveCallback, false); showbtn(); hidebtn(path_button_3); }; //path button 4 this.path_button_4.enabled = true; this.path_button_4.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_4.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_4.onPress = function() { character.goToNode("node_4", characterMoveCallback, false); showbtn(); hidebtn(path_button_4); }; //path button 5 this.path_button_5.enabled = true; this.path_button_5.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_5.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_5.onPress = function() { character.goToNode("node_5", characterMoveCallback, false); showbtn(); hidebtn(path_button_5); }; //path button 6 this.path_button_6.enabled = true; this.path_button_6.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_6.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_6.onPress = function() { character.goToNode("node_6", characterMoveCallback, false); showbtn(); hidebtn(path_button_6); }; //path button 7 this.path_button_7.enabled = true; this.path_button_7.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_7.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_7.onPress = function() { character.goToNode("node_7", characterMoveCallback, false); showbtn(); hidebtn(path_button_7); }; //path button 8 this.path_button_8.enabled = true; this.path_button_8.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_8.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_8.onPress = function() { character.goToNode("node_8", characterMoveCallback, false); showbtn(); hidebtn(path_button_8); }; //path button 9 this.path_button_9.enabled = true; this.path_button_9.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_9.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_9.onPress = function() { character.goToNode("node_9", characterMoveCallback, false); showbtn(); hidebtn(path_button_9); }; //path button 10 this.path_button_10.enabled = true; this.path_button_10.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_10.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_10.onPress = function() { character.goToNode("node_10", characterMoveCallback, false); showbtn(); hidebtn(path_button_10); }; //path button 11 this.path_button_11.enabled = true; this.path_button_11.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_11.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_11.onPress = function() { character.goToNode("node_11", characterMoveCallback, false); showbtn(); hidebtn(path_button_11); }; //path button 12 this.path_button_12.enabled = true; this.path_button_12.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_12.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_12.onPress = function() { character.goToNode("node_12", characterMoveCallback, false); showbtn(); hidebtn(path_button_12); }; //path button 13 this.path_button_13.enabled = true; this.path_button_13.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_13.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_13.onPress = function() { character.goToNode("node_13", characterMoveCallback, false); showbtn(); hidebtn(path_button_13); }; //path button 14 this.path_button_14.enabled = true; this.path_button_14.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_14.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_14.onPress = function() { character.goToNode("node_14", characterMoveCallback, false); showbtn(); hidebtn(path_button_14); }; //path button 15 this.path_button_15.enabled = true; this.path_button_15.onRollOver = function() { _root.module.cursor.setState("walk"); }; this.path_button_15.onRollOut = function() { _root.module.cursor.resetState(); _root.cursor.stats = ""; }; this.path_button_15.onPress = function() { character.goToNode("node_15", characterMoveCallback, false); showbtn(); hidebtn(path_button_15); }; //button hiding script function hidebtn(btn:Button) { btn.enabled = false; btn._visible = false; trace("button "+btn+" hidden"); } //switch for enabling all buttons function showbtn() { var button:String = "path_button_"; for (var i = 1; i<=15; i++) { //trace(button+i); i.toString(); this[button+i]._visible = true; this[button+i].enabled = true; } trace("all buttons are shown"); }




Reply With Quote