Invalid Cast

In my quest to static-ify my code I have an Invalid Cast error which I can’t figure out.

The code is simple enough

for(x=0 ; x<textLine.Length ; x++)
		{
			if (q==0)
			{
				print("Question="+textLine[x]);
				question=textLine[x];
			}
			else if (q<=numberOfCorrectAnswers)
			{
				print("Correct Answer="+textLine[x]);
				correctAnswers[q-1]=textLine[x];
			}
			else
			{
				print("Wrong Answer="+textLine[x]);
				wrongAnswers[(q-numberOfCorrectAnswers)-1]=textLine[x];
			}
			
			q++;
			if (q>numberOfAnswersPerQuestion){q=0;}
		}

and the error I get is InvalidCastException:Cannot cast from source type to destination type. The error points to the line question=textLine[x];
Note that question is defined earlier in the script as var question :String;

Any ideas?

and as what is the array defined?

If it is defined as nothing, try adding “as String” to each line where you use it.

I have it defined just before the code runs as…

var textLine:Array=new Array(String);

?

It worked…

question = textLine[x] as String;

Thanks Again!!!