Copy link to clipboard
Copied
I'm experimenting with a q/a application in Flash. Textfield is showing a question. Another inputfield is below for answering. When answering with text, an unformulated sentence can be correct, but not according to what the code expects. In that case I want to write down many different versions of the answer. Questions arrive from an Array. Another Array tells the answer.
For example
var questions:Array = new Array;
questions[0] = ("How many cars");
answer:Array = new Array;
answer[0] = ("one", "1", "One", "ONE")
The case:
In a function where an if statement is waiting for the inputfield to have the correct answer, how does one write the code?
Example:
(...) function submit (MouseEvent) {
if (inputField == ?) {}
else {trace("wrong")}
}
Posted via phone, my computer with the actual code doesn't have internet... Should have uploaded the code I know...
Maybe what you're looking for is
if (answers[currentQuestionNum].indexOf(inputField.text) > -1) {
//something
} else {
trace('wrong');
}
Copy link to clipboard
Copied
Maybe what you're looking for is
if (answers[currentQuestionNum].indexOf(inputField.text) > -1) {
//something
} else {
trace('wrong');
}
Copy link to clipboard
Copied
It worked! Thank you so much!
I didn't quite understand the "< -1" part though. What difference does it make?
Copy link to clipboard
Copied
You're checking to see if the answer is at any index in the array that contains the admissible answers for that question. Note that it seems like the "make a link in text" functionality is currently broken in the forums, so pretend the word "checking" above links to this Array - Adobe ActionScript® 3 (AS3 ) API Reference
Copy link to clipboard
Copied
I understand, thanks!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now