Arrays: Null object reference

Hello

I’m trying to migrate a page turning animation from AS2 to AS3. The open source code is not my own, and I had started actionscript with AS3. With the below code, I get the error, “Error #1009: Cannot access a property or method of a null object reference.”

It seems to happen on the “pageOrder[page] = ename;” line. I thought that maybe the arrays disappeared when exiting the function, but even when I moved the array declarations outside the function, I still get the problem. I don’t know if the problem lies in its AS2 roots or my own misunderstanding of arrays. Any help would be appreciated, thanks.

function addPage(ename:String,tear:Boolean) { //defining pages… -------------------------------------------------------------------------------------------
if(ename==“start”)
{
var pageOrder:Array = new Array();
var pageCanTear:Array = new Array();
page=0;
ename=“blankpage”;
}

if(ename=="end") {
    var maxpage:int = page-1;
    ename="blankpage";
}
if(tear == undefined)
{tear = false;}

pageOrder[page] = ename;
pageCanTear[page] = tear;

page = page + 1;

}