Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple quiz score

Explorer ,
Feb 02, 2018 Feb 02, 2018

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.

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2018 Feb 02, 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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 03, 2018 Feb 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2018 Feb 03, 2018

Hi!

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

Thanks,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 03, 2018 Feb 03, 2018

Hi,

I'd better not share the file without my client's consent and they wont be contactable until Monday.

If someone can provide an example of a button that adds the value of one to a dynamic text box on the same timeline I'm sure I could take it from there. So if there's a set of 10 buttons and each one is clicked the value in the text box will be 10.

I've searched the forum and I can find lots of much more complicated ways of doing this because it's combined with timers and such things.

I think what I'm trying to achieve is much simpler but I just can't work it out at the moment.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2018 Feb 03, 2018

Got it.

Try this:

import flash.events.MouseEvent;

var score:uint = 0;

function clickHandler(e:MouseEvent):void

{  

    score++;

    txt.text = String(score);

}

button0.addEventListener(MouseEvent.CLICK, clickHandler);

button1.addEventListener(MouseEvent.CLICK, clickHandler);

button2.addEventListener(MouseEvent.CLICK, clickHandler);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 05, 2018 Feb 05, 2018

Hi and thanks very much for your valuable info.

It works as you can see in the attached file. I've got the buttons working on the main timeline AND where the buttons and total text box are in different movie clips.

So that proves it works and there's no problem with the file paths or whatever in my code.

It raises the question of trying to achieve this when the buttons and the total box are in a slide gallery which I've implemented with the code snippet as follows:

Multitouch.inputMode = MultitouchInputMode.GESTURE;

var currentGalleryItem:Number = 1;

var totalGalleryItems:Number = 15;

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeToGoToNextPreviousFrame);

function fl_SwipeToGoToNextPreviousFrame(event:TransformGestureEvent):void

{

if(event.offsetX == 1)

{

if(currentGalleryItem > 1){

currentGalleryItem--;

slideRight();

}

}

else if(event.offsetX == -1)

{

if(currentGalleryItem < totalGalleryItems){

currentGalleryItem++;

slideLeft();

}

}

}

, , , ,  , ,  ,  etc and so on.

So the buttons are within the slide gallery (not on the main stage) and the total box is in another movie clip on the 15th slide (page or whatever you want to call it) of the slide gallery

So I think this means the buttons aren't "connecting" with the variable/total box because it hasn't swiped on to the stage yet?

I hope that makes sense. If I've got it working on the stage without the swipe gallery, that identifies it as an issue with using the swipe gallery . . . . right??

I have sent you a link to the file on Google Drive via a direct message if it helps clarify.

Thanks again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Hi again!

Thank you for sharing your file.

I have to apologize because I really don't get what you want to do...

Do you want a gallery with all those buttons and each of them adds 1 to a score variable and text that are outside the gallery?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 06, 2018 Feb 06, 2018
LATEST

Hi,

I've got another file if you don't mind looking at it. I think it will make what I'm trying to do clearer.

Basically, I'm building a quiz. It consists of 14 pictures of Welsh castles which users are supposed to test their knowledge and guess the name of each castle.

Each picture has 4 possible choices (buttons) only one of which is correct and scores 1 point.

So those images are in a sliding gallery. The total text box is in another movie clip inside the moving gallery (that's because I want the user to click a button to reveal their score).

I'll private message more info to you.

Thanks for you support.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines