PDA

View Full Version : Fill In The Blank



apple
September 3rd, 2003, 09:15 PM
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.

jingman
September 3rd, 2003, 09:52 PM
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?

apple
September 4th, 2003, 01:23 AM
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.

jingman
September 4th, 2003, 01:43 AM
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.

grandsp5
September 4th, 2003, 01:49 AM
try textField.restrict = "";

apple
September 4th, 2003, 02:58 AM
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??

kode
September 4th, 2003, 03:34 AM
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. ;)
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary776.html

apple
September 4th, 2003, 04:07 AM
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??

kode
September 4th, 2003, 04:22 AM
I guess you could use the indexOf method of the String object.
// 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
}
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

apple
September 4th, 2003, 04:37 AM
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.

kode
September 4th, 2003, 02:40 PM
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.

apple
September 4th, 2003, 10:49 PM
kode, below is my whole code:
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 = "";
};
}
}
}
};
Please use tags to show your code. Thank you.

apple
September 4th, 2003, 10:50 PM
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.

apple
September 4th, 2003, 11:36 PM
Kode, this is the html file of my interaction.

kode
September 5th, 2003, 02:50 AM
Your HTML file is useless to me (you should have attached the FLA!), now I get to guess...
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);
...Try that.

apple
September 5th, 2003, 04:06 AM
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.

kode
September 5th, 2003, 04:38 AM
1 and 2)
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);
3) Do you really think people are that stupid? If they type a space, the answer is wrong; period. :P
I think you shouldn't worry about that.

apple
September 5th, 2003, 05:18 AM
But, if the correct answer is two words like "China town", So, what should i do.

kode, do you know how to convert an array to string??

Thanks.

kode
September 5th, 2003, 05:38 AM
Then remove the restrict line! Again, I think you shouln't worry about that. The answer is either right or wrong, and that's it. :P

And yes, I know how to convert an array to string. You use Array.join method.

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary061.html

apple
September 7th, 2003, 10:42 PM
kode, thanks for the help. I finally got what i want. I was using the join method.

By the way, as i was doing this, something has come to my mind. What if i checking an numeric answer. For example, the correct answer is 15. But, i type in 0015, 15.0 and these answers are acceptable. So, what should do to absolute it to become 15?

Thanks.