Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Referring to multiple objects in Arrays

Guest
May 10, 2014 May 10, 2014

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

TOPICS
ActionScript
328
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , May 10, 2014 May 10, 2014

Maybe what you're looking for is

if (answers[currentQuestionNum].indexOf(inputField.text) > -1) {

     //something

} else {

     trace('wrong');

}

Translate
Guide ,
May 10, 2014 May 10, 2014

Maybe what you're looking for is

if (answers[currentQuestionNum].indexOf(inputField.text) > -1) {

     //something

} else {

     trace('wrong');

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 10, 2014 May 10, 2014

It worked! Thank you so much!

I didn't quite understand the "< -1" part though. What difference does it make?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 10, 2014 May 10, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2014 May 11, 2014
LATEST

I understand, thanks!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines