0

I have a dynamic class, which has an array declared normally, before runtime.

Usually, you can dynamically access a variable, whether it has been declared or not with

myClass["variable"] = 4;

however, trying to do this with an array, like so

myClass["array[0]"] = 4;

does not store 4 into the first element of array, and instead stores it into the variable "array[0]".

For instance, after executing the previous code,

trace(myClass.array[0]);

traces undefined, where as

trace(myClass["array[0]"]);

traces 4.

Is there anyway I can access the elements of the array dynamically?

1 Answer 1

5

Don't think of it as evaluating a String. It's still just a chain of properties.

So the practical answer to your question is:

var o:Object = {};
o["array"] = [];   //we do have to insantiate the array first
o["array"][0] = 4;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - that does what I want.

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.