Flash variables

Associate
Joined
30 Dec 2005
Posts
415
Ok i've got a number of variables -
item0
item1
item2
item3
item4 etc etc...

They all contain strings.

I have a for loop, which increments the value of i each time it loops.
I have a variable called screen, which needs to equal the value of item i.

Please note, I cannot use an array in this case. Just wondering how you concatonate variable names together :)

Cheers,
Rich
 
screen = ["item" + i];

When i = 1, screen will be equal to item1
When i = 3, screen will be equal to item3

etc
 
Last edited:
Try it like

screen = this["item" + i];

I did a little test on my flash and that outputs the value of item3 etc instead of just "item3".
 
Perfect :) Thanks to you both

Just to expand upon this a bit:
I'm trying to make both variables global... var i works fine, but i'm struggling with making item global.
Code:
screen = this[_global.+"item" + _global.i];
Doesn't work and produces an error. Any ideas on the syntax for making item global?
 
Last edited:
Does anyone have those days where Flash just completely falls out with you?

I'm trying to make it read all those item variables from an external file, and it kind of works..
Code:
_global.i = 0;
loadVariables("http://localhost:8081/includes/ticker.php", "/");
_global.item0 = item0;
_global.item1 = item1;
_global.item2 = item2;
_global.item3 = item3;
_global.item4 = item4;
_global.item5 = item5;
_global.item6 = item6;
_global.item7 = item7;
_global.item8 = item8;
_global.item9 = item9;
_global.item10 = item10;
_global.item11 = item11;
_global.item12 = item12;
_global.item13 = item13;
_global.item14 = item14;
_global.item15 = item15;
_global.item16 = item16;
_global.item17 = item17;
_global.item18 = item18;
_global.item19 = item19;
_global.item20 = item20;
_global.item21 = item21;
_global.item22 = item22;
_global.item23 = item23;
_global.item24 = item24;
_global.item25 = item25;
_global.item26 = item26;
_global.item27 = item27;
_global.item28 = item28;
_global.item29 = item29;
trace(item3);

I know its crude but i'm fed up with it! Currently trace says all those variables are undefined (item1, item2 etc..), but if you create a dynamic textbox and assign say, item1 to it, it prints the value! aaah!

If I can get the above working, I can keep the
Code:
screen = this[item" + _global.i];
as I know that works.

Can anyone help me forgive flash?
 
Last edited:
Back
Top Bottom