Argument out of range - Generic list (JS)

I’m using a class to organize many arrays into an object. Then using that object to tell my game what to do at certain stages. This error is thrown ArgumentOutOfRangeException: Argument is out of range and I have no idea why. Here’s my code for accessing the list:

import System.Collections.Generic;

var skin: GUISkin;

function OnGUI() {
	GUI.skin=skin;
	var item = Stage.Stages[0];
}

And this is my code for the stage class:

import System.Collections.Generic;

class Stage
{
    var controlArray: String[];
    var taskName: String[];
    var taskStatus: Texture2D[];
    var PC: boolean;
    var arrowArray: GameObject[];
}

//what a stage object might look like
var Stage16 = new Stage();
Stage16.controlArray[0] = "";
Stage16.taskName[0] = "findTheWaterCooler";
Stage16.taskName[1] = "returnToYourDesk";
Stage16.taskName[2] = "dropToTheGround";
Stage16.taskName[3] = "coverUnderTheDesk";
Stage16.taskName[4] = "holdDuringTheEarthquake";
Stage16.taskName[5] = "dustYourselfOff";
Stage16.taskStatus[0] = Resources.Load("check_box_checked");
Stage16.taskStatus[1] = Resources.Load("check_box_failed");
Stage16.taskStatus[2] = Resources.Load("check_box_checked");
Stage16.taskStatus[3] = Resources.Load("check_box_checked");
Stage16.taskStatus[4] = Resources.Load("check_box_checked");
Stage16.taskStatus[5] = Resources.Load("check_box_empty");
Stage16.PC = false;
Stage16.arrowArray[0] = null;

static var Stages : List.<Stage> = new List.<Stage>(21);
Stages[0] = Stage0;
Stages[1] = Stage1;
Stages[2] = Stage2;
.
.
//and so on

I don’t understand why its giving me a index out of range error?? Please help!

I’m not as familiar with Javascript, but it seems that you’d have to initialize the array before accessing it:

Ie, doing this,

var taskName: String[]

and then this:

Stage16.taskName[0] = "findTheWaterCooler";
Stage16.taskName[1] = "returnToYourDesk";
Stage16.taskName[2] = "dropToTheGround";
Stage16.taskName[3] = "coverUnderTheDesk";
Stage16.taskName[4] = "holdDuringTheEarthquake";
Stage16.taskName[5] = "dustYourselfOff";

seems like a problem. I think you have to initialize it first:

taskName = new String[6]

Try breaking this

static var Stages : List. = new List.(21);

up into this:

static var Stages : List.<Stage>;

function Start()
{
 Stages = new List.<Stage>(21);
}