Skip to main content
Participant
December 21, 2021
Question

I'm doing a quiz but the result of the quiz is doubled. here's the code

  • December 21, 2021
  • 1 reply
  • 184 views

stop();

var Mark:int = 0;

btn_start.addEventListener(MouseEvent.CLICK, startquiz);

function startquiz(e:MouseEvent) : void {
gotoAndStop("q1")
}

function right_ans(next_question:String) : Function {
return function(e:MouseEvent) : void{
Mark++;
gotoAndStop(next_question);
}
}

function wrong_ans(next_question:String) : Function {
return function(e:MouseEvent) : void{

gotoAndStop(next_question);
}
}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
December 22, 2021

why are you returning a function instead of using:

 

function right_ans(next_question:String) : void {
Mark++;
gotoAndStop(next_question);
}

function wrong_ans(next_question:String) : void {
gotoAndStop(next_question);
}

Participant
December 23, 2021

Cause i put code for the question in the next frame.

q1_r.addEventListener(MouseEvent.CLICK, right_ans("q2"));

q1_w0.addEventListener(MouseEvent.CLICK, wrong_ans("q2"));

q1_w1.addEventListener(MouseEvent.CLICK, wrong_ans("q2"));

q1_w2.addEventListener(MouseEvent.CLICK, wrong_ans("q2"));

 

removing the return function breaks it

Scene 1, Layer 'AS3', Frame 332, Line 1, Column 41 1067: Implicit coercion of a value of type void to an unrelated type Function.

kglad
Community Expert
Community Expert
December 23, 2021

what code are you using that triggered that 1067 error message?