Hey guys, this function removes the over state of my buttons and it goes all the way up to 20! this code exists within a greater code that you may be able to use (since it already has a for loop). If not just ignore the extra code
Basically I want to do what the title says: enhance my code dynamically. The for loop already goes from 1 - 20 I just need to learn how to make it work for me. something like “q”+*;
function clearAll() {
if(_root.currentlyLoaded != “q1”){ q1.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q2”){ q2.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q3”){ q3.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q4”){ q4.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q5”){ q5.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q6”){ q6.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q7”){ q7.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q8”){ q8.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q9”){ q9.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q10”){ q10.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q11”){ q11.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q12”){ q12.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q13”){ q13.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q14”){ q14.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q15”){ q15.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q16”){ q16.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q17”){ q17.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q18”){ q18.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q19”){ q19.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q20”){ q20.gotoAndStop(“up”); }
}
Extra code is
//Creates the empty variable of currentlyLoaded
var currentlyLoaded = “”;
//Creates numbers to be displayed next to questions (I’LL ASK ABOUT THIS SHORTLY!)
q1.numberDisp = “1”;
q2.numberDisp = “2”;
q3.numberDisp = “3”;
q4.numberDisp = “4”;
//Creates array to hold answers
var answer = new Array();
answer[0] = “Answer 1 goes here”;
answer[1] = “Answer 2 goes here”;
answer[2] = “Answer 3 goes here”;
answer[3] = “Answer 4 goes here”;
answer[4] = “Answer 5 goes here”;
answer[5] = “Answer 6 goes here”;
answer[6] = “Answer 7 goes here”;
answer[7] = “Answer 8 goes here”;
answer[8] = “Answer 9 goes here”;
answer[9] = “Answer 10 goes here”;
answer[10] = “Answer 11 goes here”;
answer[11] = “Answer 12 goes here”;
answer[12] = “Answer 13 goes here”;
answer[13] = “Answer 14 goes here”;
answer[14] = “Answer 15 goes here”;
answer[15] = “Answer 16 goes here”;
answer[16] = “Answer 17 goes here”;
answer[17] = “Answer 18 goes here”;
answer[18] = “Answer 19 goes here”;
answer[19] = “Answer 20 goes here”;
//Creates array to hold Questions
var question = new Array();
question[0] = “Question Number 1”;
question[1] = “Question Number 2”;
question[2] = “Question Number 3”;
question[3] = “Question Number 4”;
question[4] = “Question Number 5”;
question[5] = “Question Number 6”;
question[6] = “Question Number 7”;
question[7] = “Question Number 8”;
question[8] = “Question Number 9”;
question[9] = “Question Number 10”;
question[10] = “Question Number 11”;
question[11] = “Question Number 12”;
question[12] = “Question Number 13”;
question[13] = “Question Number 14”;
question[14] = “Question Number 15”;
question[15] = “Question Number 16”;
question[16] = “Question Number 17”;
question[17] = “Question Number 18”;
question[18] = “Question Number 19”;
question[19] = “Question Number 20”;
//For loop creates function that can be reused for up down and over states
for(i=1;i<20;i++) {
_root[“q”+i].answer = _root.answer*;
_root[“q”+i].onRollOver = function() {
if(_root.currentlyLoaded != this._name){this.gotoAndStop(“over”); } }
_root["q"+i].onRollOut = function() {
if(_root.currentlyLoaded != this._name){
this.gotoAndPlay("up"); } }
_root["q"+i].onRelease = function() {
this.gotoAndStop("down");
if(_root.currentlyLoaded != this._name){
_root.currentlyLoaded = this._name
_root.answer = this.answer;
_root.clearAll(); }
}
}
//Here is the function I need to change. NOT DYNAMIC AT ALL
function clearAll() {
if(_root.currentlyLoaded != “q1”){ q1.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q2”){ q2.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q3”){ q3.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q4”){ q4.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q5”){ q5.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q6”){ q6.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q7”){ q7.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q8”){ q8.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q9”){ q9.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q10”){ q10.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q11”){ q11.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q12”){ q12.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q13”){ q13.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q14”){ q14.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q15”){ q15.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q16”){ q16.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q17”){ q17.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q18”){ q18.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q19”){ q19.gotoAndStop(“up”); }
if(_root.currentlyLoaded != “q20”){ q20.gotoAndStop(“up”); }
}