Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
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.
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
Thanks, global things are working but score and countdown aren't..
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now