all groups > flash actionscript > february 2008 >
You're in the

flash actionscript

group:

Create dynamic global variable?


Create dynamic global variable? Marc?lio Catarino
7/6/2006 1:45:08 PM
flash actionscript:
It is possible to create dynamically a global variable? I started to develop a
Flash application that load some external variables (loadVars). I have to
transform the loaded variables into global variables. The problem is that
external txt file may to contain different variables names, and some variables
sometimes may not exist. So, I can't know accurately which and how many
variables must be transformed into globals. Somebody knows a way to do that?
Re: Create dynamic global variable? samdl1
7/6/2006 2:11:46 PM
Why is it you need to make global vars? There are very few times when this is
necessary.

If it is appropriate I would recomend defining an array at the beginning of
the script and then when your LoadVars object is loaded use a for...in loop and
array.push() method to fill up the array with your LoadVars details.

I'm sorry if this is unhelpful but you need to put down more info if you want
a more concise answer

Sam
RE: Create dynamic global variable? Somnus
2/29/2008 1:44:35 PM
This was driving me crazy too. Here is the best method I found:

dot notation won't work this way, so we use the brackets:

_global["varname"] = 'info'; //normal global declaration with brackets

and the dynamic example...

color = "hot_pink"; //I'm dynamic!
_global[color] = 'ugly'; //so now trace(hot_pink) would output "ugly"

From http://www.developmentnow.com/g/69_2006_7_0_0_784385/Create-dynamic-global-variable.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button