1

I'm looping over an array named shopData and need to use values within that array to create new variables. Inside the loop, I'm trying something like this:

shop_(shopData[i].shopName).keyword = shopData[i].keyword;

but I'm having trouble with the portion in () and can't seem to find the right syntax for this.

Assuming shopData[i].shopName = "foo" I need to create a variable named:

shop_foo.keyword = value

or if shopData[i].shopName = "orange":

shop_orange.keyword = value

Is this even possible with AS2?

1 Answer 1

3

Yes, it's possible. You have to create a string representation of the variable name and use [ ] brackets:

this["shop_" + shopData[i].shopName].keyword = shopData[i].keyword;

All shop_... variables must either be member variables of a class instance (they are members of this in the above example) or you have to create a simple Object container:

var shops:Object = {};
shops["shop_" + shopData[i].shopName].keyword = shopData[i].keyword;

Just writing ["shop_" + shopData[i].shopName] to access a local variable will not compile.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.