PDA

View Full Version : variable's value as a new variable's identifier!!


yusuf_memon
06-03-2010, 06:58 AM
hello guys... sorry i can't explain it properly. I want to use a command something like:

for (var i:Number = 0; i < 5; i++) {
var myVariable:String = "hello" + String(i);
trace(myVariable);
//which will show hello0, hello1, hello2, hello3, hello4
//here I want to declare a variable, whoose identifier (name) will be the value of myVariable.
//actionscript should understand this as follow:
//var hello1:String = ....;
//var hello2:String = ....;
//var hello3:String = ....;
}

I hope it is somewhat clear to understand.

TMA-1
06-03-2010, 07:42 AM
I don't belive you can declear variables dynamicly, but using an array rather then a variable could get you where you want. Something like this:


var hello:Array = new Array();

for (var i:Number = 0; i<5; i++) {
hello[i]="Number:"+i;
trace(hello[i]);
}