Arrays within custom Classes - same array for different instances?
Hello all,
I have made a very simple custom class for keeping track of groups of offices for a company. The class has a Number variable to tell it how many different offices there are, and an Array to store the individual offices by name. It looks like this.
class officeCluster
{
static var _className:String = "officeCluster";
// variables
var numOffices:Number;
var locationArray:Array = new Array();
// functions
function officeCluster()
{
trace("officeCluster constructor");
}
}
Very simple!
Now, it is my understand that when I create different instances of the class, they will each have their own version of "numOffices" and their own version of "locationArray".
When I run traces of "numOffices", this seems to be true. For example,
trace(manufacturingOfficeCluster.numOffices);
trace(servicesOfficeCluster.numOffices);
yields
5
4
In the output panel, which is correct. However, there is trouble with the locationArray. It seems that as I assign different values to it, regardless of what instance I specify, there is only ONE array- NOT one for each instance.
In other words,
trace(manufacturingOfficeCluster.locationArray[1].theLocation); // theLocation is a String. The locationArray itself holds Objects.
trace(servicesOfficeCluster.locationArray[1].theLocation);
yields
New Haven, CT
New Haven, CT
even though I have defined elsewhere that they are different!
Is anyone aware of any issues partaining to using Arrays within Class instances? Any help would be appreciated!
note: I've been able to work around this by creating multiple arrays within the class and using a different one for each instance, but this seems very sloppy.