flash - How do I use variable variable names in Actionscript 2? -
i'm looping on array named shopdata , need use values within array create new variables. inside loop, i'm trying this:
shop_(shopdata[i].shopname).keyword = shopdata[i].keyword;
but i'm having trouble portion in () , can't seem find right syntax this.
assuming shopdata[i].shopname = "foo" need create variable named:
shop_foo.keyword = value
or if shopdata[i].shopname = "orange":
shop_orange.keyword = value
is possible as2?
yes, it's possible. have create string representation of variable name , use [ ] brackets:
this["shop_" + shopdata[i].shopname].keyword = shopdata[i].keyword;
all shop_...
variables must either member variables of class instance (they members of this
in above example) or have create simple object container:
var shops:object = {}; shops["shop_" + shopdata[i].shopname].keyword = shopdata[i].keyword;
just writing ["shop_" + shopdata[i].shopname]
access local variable not compile.
Comments
Post a Comment