i need some help. i have some code but its stupidly long:
if(_global.ticker == 1){
_global.info = text1
}
if(_global.ticker == 2){
_global.info = text2
}
if(_global.ticker == 3){
_global.info = text3
}
if(_global.ticker == 4){
_global.info = text4
}
//ect...
Please help and could you explain the code too, thanks
Stupid Saint
Try this…
_global.ticker = 2;
_global.info = "nothing";
// Assuming that text1 ~ text 4 are setup like so...
var text1:String = "text1 String";
var text2:String = "text2 String";
var text3:String = "text3 String";
var text4:String = "text4 String";
// Number of text strings.
var numOfText:Number = 4;
// Loops through from 1 to numOfText (4).
// For more info search for "for statement" in the help doc.
for(var a:Number = 1; a <= numOfText; a++) {
if(_global.ticker == a){
// info gets assigned the value of variable name "text" + a.
_global.info = this["text" + a];
// Check that the right value was assigned.
trace(_global.info);
}
}
Note: this can also be done with arrays.