Inside my Document Class I have assign to an array some objects that are placed on stage so I can call them later.
When I declare the array outside the constructor the objects haven’t been created and the assign values are null unlike when I declare them inside constructor.
Why is this happening?
How can I avoid this?Can I use a listener to track when objects are loaded?
First Case
package {
public class Document extends MovieClip {
var obj:Array = [object1,object2];
public function Document() {
trace(obj[0]); // <-- null
}
}
}
Second Case
package {
public class Document extends MovieClip {
public function Document() {
var obj:Array = [object1,object2];
trace(obj[0]); // <-- reference value
}
}
}



Declare the array outside, and stuff values inside the constructor.
Whatever you write as initialized value is processed first, anything embedded in editor is second, the constructor code is third. So, when you refer assets by name in initialization code, they are yet uninitialized, so you receive nulls.
Whatever listeners you use will only get applied after the object will be available.
init()andADDED_TO_STAGElisteners are useful if you need stage reference to align your code-controlled asset to given stage dimensions. Before that happens, the stage reference is null.