“This” is incapable of finding the appropriate variable “array1” despite it clearly being declared within the function. But if I declare the variables outside of the function it works. How can I have the variables inside the function but keep it working?
package
{
public class main extends MovieClip
{
//If I declared the variables here it would work.
public function main():void
{
var array1:Array = [1,2];
var array2:Array = [3,4];
trace(this["array"+1][1]); //returns reference error 1069
}
}
}
Am I stuck with declaring the variables outside of the function?
And no, multidimensional arrays won’t work for what I need it for. Though it looks like it would solve everything within the code snippet provided huh?
My intentions is to pass arrays through a class to be used and change which array bunch I use. If I used multidimensional arrays, it would be inefficient due to the amount of copying that would occur.
For
this[]to access properties, those properties must belong tothis. In your sample, the properties belong to the function in which they were defined and are inaccessible outside of that scope.So firstly; yes, for your code to work you will of course need to define properties in the class level scope.
But more importantly I’d look closely at what you’re trying to do and determine whether it’s a good approach – my bet is that it’s not. It seems like you may want to consider an isolated class that deals with all the data you want to store.