Return reference to object added to an array (Javascript)

I have a very simple issue. I’m adding an object and trying to return a reference to that object using the following code…

public var pages: Page[];

public function AddPage (obj : Page) {
   pages += [obj];
   return pages[pages.Length-1]; //return handle to object
}

Now I call this like so

var myTestPage = myAdventure.AddPage( new Page("testPage") );

and get this error

Object reference not set to the instance of an object.

Now there doesn’t seem to be any issue with the construction of the object as calling AddPage without assigning to an object works fine and can be referenced perfectly.

Many thanks in advance!

Arrays are fixed-length and can’t have items added to them. Use a generic List instead.