I have a class that has a lot of functions, and a couple of functions need to use the same array of instances. In order to shorten code, I should create a global array with these instances and all functions in this class can access it, however when I create it, every instance inside turns "null" and no function can access it.
ActionScript Code:
package {
//imports
public var portraitsArray:Array = [
[instance1, instance2, instance3],
[instance4, instance5, instance6]
];
public function Story() {}
...
...
public function start() {
...
...
for each (var portrait:MovieClip in portraitsArray[0])
{
portrait.alpha = 0;
}
}
public function next() {
...
...
for each (var portrait:MovieClip in portraitsArray[1])
{
portrait.alpha = 1;
}
}
}
Running this code above will return every instance inside portrairsArray as null, thus functions will return null errors.
This is just example, performing function on instances inside the array.
However, this code below works, although being very redundant:
ActionScript Code:
package {
//imports
public function Story() {}
...
...
public function start() {
...
...
var portraitsArray:Array = [
[instance1, instance2, instance3],
[instance4, instance5, instance6]
];
for each (var portrait:MovieClip in portraitsArray[0])
{
portrait.alpha = 0;
}
}
public function next() {
...
...
public var portraitsArray:Array = [
[instance1, instance2, instance3],
[instance4, instance5, instance6]
];
for each (var portrait:MovieClip in portraitsArray[1])
{
portrait.alpha = 1;
}
}
}
Does anyone know why I can't access those instances as global array?