Error #1009: Cannot access a property or method of a null object reference
I'm trying to create a simple quiz, and it kind of works, but it pops up that error seemingly at random and I can't wrap my head around it.
The quiz works by having a pool of 10 questions, each on a different frame. It starts by clicking a button, which uses this code:
StartQuiz.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);
//A che domanda siamo nel quiz
var QNumber:Number = 0;
//frame delle domande
var Qarray:Array = [2,3,4,5,6,7,8,9,10,11];
function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
this.PName = PlayerName.text;
//Prendo un numero da 0 alla lunghezza dell'array
var i:Number = (Math.floor(Math.random() * Qarray.length));
//Quel numero è la posizione nell'array della prossima domanda
var ProxFrame:Number = Qarray[i];
//Che tolgo dall'array per evitare si ripeta
Qarray.splice(i,1);
//E mi segno a che domanda siamo per scriverla in alto e per fermarmi alla quinta
QNumber++;
trace("i=" + i);
trace("QNumber =" + QNumber);
trace(Qarray);
MovieClip(this.root).gotoAndStop( ProxFrame, "Quiz");
}to select from the array (which contains the numbers of the frames, so from frame 2 that has the first question to frame 11 which has the last one) one question and removing it so it doesn't come up again. Every frame has its own "proceed" button, which is hidden with "Proceed7.visible = false;" at the beginning so that the player can click on an answer and only then be allowed to proceed to the next question. Every Proceed button has a code similar to the one above:
Proceed5.addEventListener(MouseEvent.CLICK, NextQ5);
function NextQ5(event:MouseEvent):void
{
var i:Number = (Math.floor(Math.random() * Qarray.length));
var ProxFrame:Number = Qarray[i];
Qarray.splice(i,1);
QNumber++;
trace("i=" + i);
trace("QNumber =" + QNumber);
trace(Qarray);
if (QNumber > 5)
{
MovieClip(this.root).gotoAndStop(12, "Quiz");
}
else
{
MovieClip(this.root).gotoAndStop(ProxFrame, "Quiz");
}
}And the thing that's making me go insane is that sometimes it works just fine, but some others the error #10009 comes up, sometimes referencing the first button, sometimes one of the proceed (not always the same, and not always on the same array output, so it's not something specific I think)
This is the code that hides/reveals the proceed button, if it helps:
this.QNum.text = "" + QNumber;
Proceed6.visible = false;
Answ6.visible = false;
//Funzioni per le risposte
RispostaB6.addEventListener(MouseEvent.CLICK, RispostaGiusta6);
function RispostaGiusta6(evt:MouseEvent):void
{
SfondoRisposta6B.transform.colorTransform = new ColorTransform(0,0,0,1,0,255,0,0);
Proceed6.visible = true;
RispostaA6.visible = false;
RispostaC6.visible = false;
RispostaD6.visible = false;
}
RispostaA6.addEventListener(MouseEvent.CLICK, RispostaSbagliata6a);
function RispostaSbagliata6a(evt:MouseEvent):void
{
SfondoRisposta6A.transform.colorTransform = new ColorTransform(0,0,0,1,255,0,0,0);
Proceed6.visible = true;
Answ6.visible = true;
RispostaB6.visible = false;
RispostaC6.visible = false;
RispostaD6.visible = false;
}
RispostaC6.addEventListener(MouseEvent.CLICK, RispostaSbagliata6b);
function RispostaSbagliata6b(evt:MouseEvent):void
{
SfondoRisposta6C.transform.colorTransform = new ColorTransform(0,0,0,1,255,0,0,0);
Proceed6.visible = true;
Answ6.visible = true;
RispostaB6.visible = false;
RispostaA6.visible = false;
RispostaD6.visible = false;
}
RispostaD6.addEventListener(MouseEvent.CLICK, RispostaSbagliata6c);
function RispostaSbagliata6c(evt:MouseEvent):void
{
SfondoRisposta6D.transform.colorTransform = new ColorTransform(0,0,0,1,255,0,0,0);
Proceed6.visible = true;
Answ6.visible = true;
RispostaB6.visible = false;
RispostaC6.visible = false;
RispostaA6.visible = false;
}
If anyone could help me understand I would be infinitely grateful!
