# Fill In The Blank

**URL:** https://forum.kirupa.com/t/fill-in-the-blank/30108
**Category:** flash
**Created:** [September 4, 2003, 1:15am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108 "2003-09-04T01:15:38Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![apple](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@apple](https://forum.kirupa.com/u/apple)
#### Post date: [September 4, 2003, 1:15am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/1 "2003-09-04T01:15:38Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 1:52am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/2 "2003-09-04T01:52:43Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 5:23am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/3 "2003-09-04T05:23:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 5:43am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/4 "2003-09-04T05:43:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 5:49am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/5 "2003-09-04T05:49:36Z")

</div>

try textField.restrict = “”;

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 6:58am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/6 "2003-09-04T06:58:31Z")

</div>

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??

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 7:34am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/7 "2003-09-04T07:34:37Z")

</div>

> _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](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. 😉  
[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary776.html](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary776.html)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 8:07am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/8 "2003-09-04T08:07:25Z")

</div>

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??

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 8:22am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/9 "2003-09-04T08:22:15Z")

</div>

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_dictionary692.html)  
[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary699.html](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary699.html)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 8:37am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/10 "2003-09-04T08:37:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 4, 2003, 6:40pm UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/11 "2003-09-04T18:40:52Z")

</div>

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. 🙂

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 5, 2003, 2:49am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/12 "2003-09-05T02:49:22Z")

</div>

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]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 5, 2003, 2:50am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/13 "2003-09-05T02:50:33Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 5, 2003, 3:36am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/14 "2003-09-05T03:36:06Z")

</div>

Kode, this is the html file of my interaction.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 5, 2003, 6:50am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/15 "2003-09-05T06:50:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 5, 2003, 8:06am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/16 "2003-09-05T08:06:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 5, 2003, 8:38am UTC](https://forum.kirupa.com/t/fill-in-the-blank/30108/17 "2003-09-05T08:38:29Z")

</div>

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. 😛  
I think you shouldn’t worry about that.
