Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

condensing if statements

Status
Not open for further replies.

jefargrafx

Instructor
May 24, 2001
273
US
so I got this function that check the currentframe and depending on it's number goes to the nextframe or to the next frame in a loaded movie clip.

my question, any tutorials on condenseing code?

here are 27 same but differnet if statements, there's got to be a way to shorten this?


function pageforward() {
resettitle();
if (frameLabel == "intro") {
gotoAndStop("page_01");
}
if (frameLabel == "page_01" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_02");

} else if (frameLabel == "page_01" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_02" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_03");

} else if (frameLabel == "page_02" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_03" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_04");

} else if (frameLabel == "page_03" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_04" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_05");

} else if (frameLabel == "page_04" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_05" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_06");

} else if (frameLabel == "page_05" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_06" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_07");

} else if (frameLabel == "page_06" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_07" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_08");

} else if (frameLabel == "page_07" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_08" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_09");

} else if (frameLabel == "page_08" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_09" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_10");

} else if (frameLabel == "page_09" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_10" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_11");

} else if (frameLabel == "page_10" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_11" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_12");

} else if (frameLabel == "page_11" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_12" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_13");

} else if (frameLabel == "page_12" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_13" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_14");

} else if (frameLabel == "page_13" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_14" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_15");

} else if (frameLabel == "page_14" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_15" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_16");

} else if (frameLabel == "page_15" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_16" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_17");

} else if (frameLabel == "page_16" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_17" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_18");

} else if (frameLabel == "page_17" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_18" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_19");

} else if (frameLabel == "page_18" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_19" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_20");

} else if (frameLabel == "page_19" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_20" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_21");

} else if (frameLabel == "page_20" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_21" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_22");

} else if (frameLabel == "page_21" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_22" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_23");

} else if (frameLabel == "page_22" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_23" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_24");

} else if (frameLabel == "page_23" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_24" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_25");

} else if (frameLabel == "page_24" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_25" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_26");

} else if (frameLabel == "page_25" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_26" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("page_27");

} else if (frameLabel == "page_26" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
if (frameLabel == "page_27" and _root.page_MC._currentframe == _root.page_MC._totalframes) {
gotoAndStop("intro");

} else if (frameLabel == "page_27" and _root.page_MC._currentframe != _root.page_MC._totalframes) {
_root.page_MC.nextFrame();
}
}

jef
 
you could switch on framelabel and currentframe .... may not be much help....

and should be &&
 
yes, your right && but and does work, just a habbit I guess.

I know there got to be a way to make this if statement smaller?

thanks

jef
 
try this...its on the right lines but might be quite there yet...means renaming some of the pages page_02 has become page_2

Code:
function pageforward() {
    resettitle();
x = _root.page_MC._totalframes;
y = _root.page_MC._currentframe;
my_arr = [];
for(i=1;i<28;i++)
my_arr.push(&quot;page_&quot; + i);
if (frameLabel == &quot;intro&quot;) {
    gotoAndStop(&quot;page_1&quot;);
}
for(i=0;i<my_arr.length;i++)
	if(framelabel == my_arr[i])
		if(x==y)
		gotoAndStop(my_arr[i+1])
		else
		nextFrame();
}
 
Thanks bill, I've give it a try.

Never thoguth about using an array,

that's why it always good to ask

I'll let ya know

jef
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top