Copy link to clipboard
Copied
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!
Thanks for the file.
You have a couple of mismatches when referencing buttons in your code.
For example, in frame 5 of the Quiz scene, you are trying to add an event listener to RispostaD1, but this button doesn't exist in the same frame.
Something similar happens to frame 3.
So I suggest you to double-check the references in code and the instances on stage.
Copy link to clipboard
Copied
enable debugging and find the line with the error.
Copy link to clipboard
Copied
I tried, and got
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at QuizBLS_fla::MainTimeline/frame20()[QuizBLS_fla.MainTimeline::frame20:41]
at flash.display::MovieClip/gotoAndStop()
at QuizBLS_fla::MainTimeline/NextQ6()[QuizBLS_fla.MainTimeline::frame22:73]
If with frame it refers to the literal adobe animate frame there's something wrong, since there is no frame 20 at all, and if it refers to the 20th line of code it refers to "MovieClip(this.root).gotoAndStop(ProxFrame, "Quiz");" which is random, since sometimes it works, sometimes it doesn't. My guess would be that it's related to the array, since it's the only random thing, but I can't understand how it's a problem and why it's a problem only sometimes
Copy link to clipboard
Copied
what are the few lines surrounding the problematic frame 20, line 41 (and indicate which is 41)
Copy link to clipboard
Copied
That's the thing that confuses me, the project has no frame 20, it stops at frame 13.
But since the error refers to "NextQ6" I think it's referring to frame 7, the only place where that function is called. This is the code:
this.QNum.text = "" + QNumber;
Proceed6.addEventListener(MouseEvent.CLICK, NextQ6);
function NextQ6(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 only other code in that frame is identical (changing the instances and functions obviously) to the one posted at the end of the ask
Copy link to clipboard
Copied
Hi.
Is the Quiz scene the only one you have in your FLA? What does the Scene panel show?
Regards,
JC
Copy link to clipboard
Copied
I have two other scenes (don't mind the names, I'm italian):
Risorse (Resources) can be accessed ony through the Main Menu (Menu principale), it's basically just a frame with some text. The Main Menu has a button that brings to the first frame of the Quiz scene, where the player can write their name in an input text and click on a button (the one with the startquiz functin at the beginning of my question) to start the quiz. In that first frame there's also another button to go back to the main menu, but it has never caused me any issues.
Copy link to clipboard
Copied
Alright. Thanks for the info.
Do you have a FLA that we can take a look? You can use placeholder assets if needed.
Copy link to clipboard
Copied
Thank you so much for taking the time to help!
I can't manage to attach the file to a comment here, so I made a Drive folder if that's allowed: link
Sorry for the italian, I hope it's not much of an issue.
Copy link to clipboard
Copied
you should really learn how to fix it yourself.
Copy link to clipboard
Copied
I am trying to learn, that's why I'm here in the first place 🙂
I don't want somebody to make the project for me, just to explain to me what is wrong so that I can actually understand, since right now I have no idea where the problem is.
I tried to count the total frames and as I tought the problem seems to be on frame 7, but as I said before, the problematic frame changes randomly (which is not a surprise, the code is the same for every question of the quiz) and I still don't understand exactly what the error is referring to, because since the code is basically the same on every frame the error should pop up at every frame. The only conclusion I can reach is that the array is causing something, but I can't manage to understand what.
Copy link to clipboard
Copied
add the total frames in main to the frames in resorse.
20 minus that total is the problematic frame in quiz.
Copy link to clipboard
Copied
Thanks for the file.
You have a couple of mismatches when referencing buttons in your code.
For example, in frame 5 of the Quiz scene, you are trying to add an event listener to RispostaD1, but this button doesn't exist in the same frame.
Something similar happens to frame 3.
So I suggest you to double-check the references in code and the instances on stage.
Copy link to clipboard
Copied
Thank you so much! I was convinced the error was in the other segmet of the code and I completely missed those. I think that was the cause of the issue since it doesn't pop up anymore. Funnily enough now the program gets stuck only if it lands on frame 2, but without any error message, so I think there's a logical fallacy somewhere in my code. I'll try to figure it out.
Thank you very much again, you were really kind!
Copy link to clipboard
Copied
You're welcome!
It's not easy to spot mistakes when working with multiple frames.
Please let us know if you need more help.
Regards,
JC
Find more inspiration, events, and resources on the new Adobe Community
Explore Now