Well this is kind of vague. Where are those objects instantiated?
I would suggest making sure they are instantiated in you class:
package
{
public class Document extends Sprite //I don't think you really need MovieClip
{
//alternatively to the method bellow you could use something like:
//
// private var object1 : Object = new Object();
// private var object2 : Object = new Object();
// public var obj : Array = [object1, object2];
//
// just make sure they are instantiated before they are used in the obj contructor
public var obj : Array = [new Object(),new Object()]; //again here I would suggest using a vector if they are the same type
public function Document()
{
trace(obj[0]);
}
}
}
If those objects are external to the class I would suggest passing them to the contructor like this:
package
{
public class Document extends Sprite //I don't think you really need MovieClip
{
public var obj : Array = [null,null]; //again here I would suggest using a vector if they are the same type
public function Document(o1:Object=null,o2:Object=null)
{
if (o1 != null)
obj[0] = o1;
if (o2 != null)
obj[1] = o2;
//
if (obj[0] != null)
trace(obj[0]);
else
trace("Obj[0] is null");
}
}
}
[LATER EDIT]
As to the reason this is happening is because at the time of the array initialization those 2 are null (they haven't been initialized yet)
[LATER EDIT2]
OK - Document is the root class of the flash - good to know
Like I said in my comments, even though on stage those 2 objects aren't instantiated until they are added to stage. for that I would suggest listening to the ADDED_TO_STAGE event.
if you pass them outside constructor they will be null when the array is created since they haven't yet been added to stage/created(contrary to popular belief, even in Flash, objects don't simply exist)