Question : Need help condensing this code, possibly using a 'for' statement

I need help streamlining this code (Actionscript 3.0)... I've got similar codes floating throughout my program and it's frustrating me to look at it, as I know there's a shorter way to write it (using a for statement and some small script that I'm not yet familiar with)... If I could get an example for condensing this using a 'for' statement (i believe that would be the best approach), I can then condense all the other lines that use this repetitive nonsense into something much more reader-friendly :)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
if(parseInt(min_mc_string[0]) == 0)
		min_cartoon.item1.txt1.gotoAndStop(10);
	else if (isNaN(parseInt(min_mc_string[0])))
		min_cartoon.item1.txt1.gotoAndStop(11);
	else min_cartoon.item1.txt1.gotoAndStop(parseInt(min_mc_string[0]));
	
	if(parseInt(min_mc_string[1]) == 0)
		min_cartoon.item2.txt1.gotoAndStop(10);
	else if (isNaN(parseInt(min_mc_string[1])))
		min_cartoon.item2.txt1.gotoAndStop(11);
	else min_cartoon.item2.txt1.gotoAndStop(parseInt(min_mc_string[1]));

	if(parseInt(min_mc_string[2]) == 0)
		min_cartoon.item3.txt1.gotoAndStop(10);
	else if (isNaN(parseInt(min_mc_string[2])))
		min_cartoon.item3.txt1.gotoAndStop(11);
	else min_cartoon.item3.txt1.gotoAndStop(parseInt(min_mc_string[2]));

Answer : Need help condensing this code, possibly using a 'for' statement

ghemstrom is on the right track, but contains a few slight typos, yet I'm really surprised how well the code is written for writing it without any previous ActionScript experience. :)

Try the attached code (where I also define the Array, which should preferably done outside of the function that you use to go to different frames. Also, I moved some of the code onto single lines to make it a bit more readable, but it is definitely possible to move those down onto the next line.

Just ask if you have any more questions regarding the code or any other ActionScript,
Andreas
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var itemsArray:Array = new Array();
itemsArray[0] = min_cartoon.item1.txt1;
itemsArray[1] = min_cartoon.item2.txt1;
itemsArray[2] = min_cartoon.item3.txt1;

for (var i:int = 0; i < itemsArray.length; i++)
{
    var value:Number = parseInt(min_mc_string[i]);
    if (isNaN(value))    { itemsArray[i].gotoAndStop(11); }
    else if (value == 0) { itemsArray[i].gotoAndStop(10); }
    else                 { itemsArray[i].gotoAndStop(value); }    
}
Random Solutions  
 
programming4us programming4us