Fill In The Blank

I’m facing a problem where i still can type in something on the blank after i displayed the correct answer (after two attempts). Why is it happened?? Hope someone can help me out. Thanks.

can I get an fla, and a more detailed description of your intended purpose. If you have posted before can I get a link to the post?

First, thanks for your reply. Actually, i using the “onEnterFrame = function()” event Handler and the condition part to check the answer is under it. Since it is a FIB, i using the key object “(Key.isDown(Key.ENTER))”.

The condition part to check the answer as below:

  1. If the given answer is “China” (the correct answer), i made the Textfield.selectable = false and deleted the onEnterFrame.

  2. As this FIB has two attempts, when i give wrong answer in the first attempt, i delete the answer after some audio by using this Textfield.text = " ";

  3. But, if i give wrong answer after 2nd attempt, i deleted the event Handle “onEnterFrame” and made the textfiled.selectable = false. Then display the answer at the end
    textfield.text = “China”;

By the way, i have two more problem. When i type in the answer with a spacing. It’s not working. And, when i pressed “ENTER” key once, the audio was playing twice. This happens sometimes and not always. So, could you hlep me out on this also. Thanks.

I’m afraid I can’t really tell what you’re problem is, or what exactly you are asking me.

So I just made an fla that I think does what you want - or should at least put you on the right track.

try textField.restrict = “”;

grandsp5, can i use this to accept the space also?? If does, what should i do??

Jingman, in your example, i still can type in somthing eventhough the correct answer has been shown. So, what should be do where we cannot type in anything after the correct answer has been shown??

Originally posted by apple
grandsp5, can i use this to accept the space also?? If does, what should i do??

Read this: http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary762.html.

Originally posted by apple
Jingman, in your example, i still can type in somthing eventhough the correct answer has been shown. So, what should be do where we cannot type in anything after the correct answer has been shown??

Set the type of the text field to dynamic. :wink:
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary776.html

Sorry, i don’t think this is what i want. Actually, for example, I enter an answer with extra space in front of the word " China", and suppose this is the correct answer. So, b4 checking the answer, i want to remove the extra space in the textfield. So, What should i do??

I guess you could use the indexOf method of the String object.
[AS]// assuming answer_txt is the instance name of the TextField
var answer_str = answer_txt.text.toLowerCase();
if (answer_str.indexOf(“china”)>0) {
// answer is right
} else {
// answer is wrong
}[/AS]
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary692.html
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary699.html

Kode, thanks for the coding. But, if i didn’t give a extra space b4 the answer i enter or give extra space after the answer "China ", it doesn’t work. And, I have another problem which is the feedback audio plays twice eventhough i press “ENTER” key once only. So, to be more clear about what i have done, please refer the code below:

ans=Inp.text.toLowerCase();

if (ans.indexOf(“china”)>0) {
Inp.selectable = false;
dlg.attachSound(“positive”);
dlg.start();
dlg.onSoundComplete = function() {
delete dlg;
};

} else {
_global.wrongCount++;
dlg.attachSound(“negative”);
dlg.start();
if (wrongCount == 2) {
Inp.text = “China”;
} else {
dlg.onSoundComplete = function() {
delete dlg;
Inp.text = “”;
};
}
}

By the way, why i still can type in something after the correct answer has displayed on the blank. For you information, i’m using onEnterFrame event Handler.

ince you said you’re using an onEnterFrame handler, the code is probably being executed twice.

It’s hard to tell without seeing all you code, either post the whole code or attach your FLA. :slight_smile:

And I told you… set the type of the text field to dynamic, so people can’t type into it.

kode, below is my whole code:
[AS]this.onEnterFrame = function() {
if (Key.isDown(Key.ENTER)) {
ans = Inp.text.toLowerCase();
delete dlg;
dlg = new Sound(this);
trace(ans);
if ((ans == “china”) || (ans.indexOf(“china”)>0) || (ans.lastIndexOf(“china”)>0)) {
Inp.selectable = false;
dlg.attachSound(“positive”);
dlg.start();
dlg.onSoundComplete = function() {
dlg.attachSound(“correct”);
dlg.start();
delete dlg;
};
delete this.onEnterFrame;
} else {
_global.wrongCount++;
trace(_global.wrongCount);
dlg.attachSound(“negative”);
dlg.start();
dlg.attachSound(“incorrect”);
dlg.start();
if (_global.wrongCount == 2) {
delete this.onEnterFrame;
Inp.selectable = false;
Inp.text = “China”;
} else {
dlg.onSoundComplete = function() {
Inp.text = “”;
};
}
}
}
};[/AS]
[EDIT by kode]Please use [AS][/AS] tags to show your code. Thank you.[/EDIT]

Kode, this is another dout that i having:

  1. Could it be done like remove the extra space of the input text before store in the variable. for example: “China”, “Chi na”, "China "

  2. The wrong feedback audio something plays twice although i only press the “ENTER” key once.

  3. I still enter something on the blank after the correct answer display on the blank (after two attempts).

In your prev reply, you said change the text to dynamic text. But, this is a fill in the blank interaction. If i change it to dynamic text, i unable to type in anything. Or could you please explain why you would like me to do that. Thanks.

Kode, this is the html file of my interaction.

Your HTML file is useless to me (you should have attached the FLA!), now I get to guess…
[AS]var dlg = new Sound(this);
var wrong = 0;
Inp.restrict = "^ ";
this.onKeyDown = function() {
if (Key.isDown(13)) {
ans = Inp.text.toLowerCase();
if (ans == “china”) {
Inp.type = “dynamic”;
dlg.attachSound(“positive”);
dlg.start();
dlg.onSoundComplete = function() {
this.attachSound(“correct”);
this.start();
delete this.onSoundComplete;
};
delete this.onKeyDown;
} else {
wrong++;
dlg.attachSound(“negative”);
dlg.start();
dlg.onSoundComplete = function() {
this.attachSound(“incorrect”);
this.start();
this.onSoundComplete = function() {
if (wrong == 2) {
Inp.type = “dynamic”;
Inp.text = “China”;
delete onKeyDown;
}
Inp.text = “”;
delete this.onSoundComplete;
};
};
}
}
};
Key.addListener(this);[/AS]
…Try that.

Kode, thanks very much and for your patient. I have tried the code that you gave. So far it works quite well except…

  1. While the wrong feedback dialog is play, i still can enter something on the blank. So, what should i do to make it not enterable at this moment??

  2. The correct answer is not showing after two attempts. What should it do??

By the way, you used restrict = "^ " to restrict the spacing, isn’t it?? But, if the answer allow to recept two words like “China town”, this cannot be used. So, in flash action script, does it has any function to find the spacing in the input text either in the front, in between or behind and then remove it instead of restrict it from the beginning.

Thanks.

1 and 2)
[AS]var dlg = new Sound(this);
var wrong = 0;
Inp.restrict = "^ ";
this.onKeyDown = function() {
if (Key.isDown(13)) {
var ans = Inp.text.toLowerCase();
if (ans == “china”) {
Inp.type = “dynamic”;
dlg.attachSound(“positive”);
dlg.start();
dlg.onSoundComplete = function() {
this.attachSound(“correct”);
this.start();
delete this.onSoundComplete;
};
delete this.onKeyDown;
} else {
Inp.type = “dynamic”;
wrong++;
dlg.attachSound(“negative”);
dlg.start();
dlg.onSoundComplete = function() {
this.attachSound(“incorrect”);
this.start();
this.onSoundComplete = function() {
if (wrong == 2) {
Inp.type = “dynamic”;
Inp.text = “China”;
delete onKeyDown;
} else {
Inp.type = “input”;
Inp.text = “”;
}
delete this.onSoundComplete;
};
};
}
}
};
Key.addListener(this);[/AS]
3) Do you really think people are that stupid? If they type a space, the answer is wrong; period. :stuck_out_tongue:
I think you shouldn’t worry about that.