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

Quiz error

Guest
Dec 12, 2014 Dec 12, 2014

Hi,

I'd love to know what's the problem with my quiz, flash says that all is ok but when I try it, there's only score text and countdown text but it doesn't work

var myscore = 0;  score.text = myscore+"";

var question:String='abc';

var answer:String='cba';

var question2:TextField=new TextField();

question2.x=334

question2.y=39

question2.text=question;

var reponse:TextField=new TextField();

reponse.x=342

reponse.y=309

// at some point check

if(reponse.text==answer){

ponv.visible=true;

myscore+=10;

  nextFrame();

} else {

ponx.visible=true;

  nextFrame();

}

var qTimer:Timer = new Timer(1000);

qTimer.addEventListener(TimerEvent.TIMER, countdownHandler);

function  countdownHandler(event:TimerEvent):void{

  countdown.text = 30-qTimer.currentCount+" s remaining";

  if(qTimer.currentCount==30){gotoAndStop(5)}

}

qTimer.start();

Thanks in advance.

TOPICS
ActionScript
194
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 ,
Dec 12, 2014 Dec 12, 2014

you're checking response.text before there's any text.  add a listener to check it when you want.

also, you probably want that to be an input text field so you need to assign it's type property.

and you want your user to see that textfield so you probably want to enable its border property.

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
Guest
Dec 13, 2014 Dec 13, 2014

Thanks for your answer again, I did what you told me to do (Not sure if it's right) but I'm still having a problem with text..

Here goes some details from my project:

CODE


var myscore = 0;  score.text = myscore+"";

var question:String='Australie';

var answer:String='Camberra';

var question2:TextField=new TextField();

question2.x=334

question2.y=39

question2.text=question;

var reponse:TextField=new TextField();

reponse.x=342

reponse.y=309

reponse.addEventListener(Event.ENTER_FRAME, reponse2);

function reponse2(event:Event):void{

if(reponse.text==answer){

  ponv.visible=true;

  myscore+=10;

  nextFrame();}

else {

  ponx.visible=true;

  nextFrame();}

}

var qTimer:Timer = new Timer(1000);

qTimer.addEventListener(TimerEvent.TIMER, countdownHandler);

function  countdownHandler(event:TimerEvent):void{

  countdown.text = 30-qTimer.currentCount+" s restants";

  if(qTimer.currentCount==30){gotoAndStop(5)}

}

qTimer.start();

IMAGES

Project - Imgur

When I try to debug it says the error is on if(reponse.text==answer){

But I don't understand why. If possible correct it on my codes and tell me what's wrong, please.

Thank you again for your help.

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 ,
Dec 13, 2014 Dec 13, 2014

that line has no error but that code is problematic.  use:

CODE


var myscore = 0;  score.text = myscore+"";

var question:String='Australie';

var answer:String='Camberra';

var question2:TextField=new TextField();

question2.x=334

question2.y=39

question2.text=question;

var reponse:TextField=new TextField();

reponse.border=true;

response.type='input'

addChild(reponse);

reponse.x=342

reponse.y=309

reponse.addEventListener(KeyboardEvent.KEY_DOWN, reponse2);

function reponse2(event:KeyboardEvent):void{

if(event.keyCode==13){  // using the enter key to indicate the answer is ready to be checked.

if(reponse.text==answer){

  ponv.visible=true;

  myscore+=10;

  nextFrame();

} else {

  ponx.visible=true;

  nextFrame();

}

}

}

var qTimer:Timer = new Timer(1000);

qTimer.addEventListener(TimerEvent.TIMER, countdownHandler);

function  countdownHandler(event:TimerEvent):void{

  countdown.text = 30-qTimer.currentCount+" s restants";

  if(qTimer.currentCount==30){gotoAndStop(5)}

}

qTimer.start();

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
Guest
Dec 14, 2014 Dec 14, 2014

Thanks, global things are working but score and countdown aren't..

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 ,
Dec 14, 2014 Dec 14, 2014
LATEST

countdown should be on its own layer with only one keyframe (in the same frame that contains that code) and there shouldn't be any timer code in subsequent frames except a qTimer.reset() and qTimer.start().

and you never update your score textfield so that's not going to reveal the myscore value.

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