Skip to main content
Inspiring
February 2, 2018
Question

Simple quiz score

  • February 2, 2018
  • 1 reply
  • 1192 views

Hi,

I've searched the forums and found lots of answers that are for much more complicated questions then this one. I can't find quite the answer I need.

Basically I have a series of images with four possible answers below them as buttons. Only one of those answers is correct.

If the user clicks on the correct button I need 1 added to the total score.

So I've created a dynamic text box (which is nested two movie clips down) and I've called that "quizresult_text"

So that is nested like this: gallery_items.quizscore_mc.quiz.result_text

I've set up a variable as you'll see in this example button.

var score:int = 0;

btn1.addEventListener(MouseEvent.CLICK, Add1);

function Add1(e:MouseEvent):void {

score = score+1;

gallery_items.quizscore_mc.quizresult_text = "" +score.toString();

}

It's not working and I'm getting this error message:

TypeError: Error #1034: Type Coercion failed: cannot convert "1" to flash.text.TextField.

at Feb1BBB_fla::MainTimeline/Add1()[Feb1BBB_fla.MainTimeline::frame1:9]

Any advice appreciated.

This topic has been closed for replies.

1 reply

JoãoCésar17023019
Community Expert
Community Expert
February 2, 2018

You're assigning the score to the text field itself not to its text property.

Should be:

gallery_items.quizscore_mc.quizresult_text.text = "" +score.toString();

Inspiring
February 3, 2018

Hi,

thanks for your response.

It's definitely got me a step closer but now the problem is only one button works. I set up 3 buttons to test, clicked on all 3 and the result in the dynamic text field at

gallery_items.quizscore_mc.quizresult_text.text = "" +score.toString();

is just the letter "a"

So only one click is working or I would be getting a "c" surely and obviously I'm getting alphabetical characters instead of numbers.

I'll carry on trying to figure this out but if you have any ideas it would probably save me some time (assuming I can eventually figure it out anyway).

Thanks again.

JoãoCésar17023019
Community Expert
Community Expert
February 3, 2018

Hi!

Would you mind sharing your FLA so I can understand what's happening?

Thanks,

JC