0

This is probably easy but I just cannot get the answer. Here is a simple Array:

I want the information to be distributed from an Input textBox to different dynamic textBox after a click. I am OK with buttons.

var ERLQ1:Array = ["ERLQ1",  "N09°02.61 / E100°49.11", "ErawanLq"];
InputText = "ERLQ1";
    //I want to display:
Txt1 = "ERLQ1"           //Being first part of the array as main reference.
Txt2 = "N09°02.61 / E100°49.11"   // Should be:   String(ERLQ1[1])
Txt3 = "ErawanLq"                 // Should be:   String(ERLQ1[2]) 

First time I write in a forum like this. Please forgive if not perfect. Thanks in advance. Andre

3
  • Please be more specific. What is your problem? Commented Nov 1, 2016 at 9:46
  • @Cherniv : If an answer solved your problem, you may mark this question as solved. This avoid people to loose some time for an issue you don't have anymore. If an answer was helpful, you may "upvote" this answer too. Anyway thank you for your feedback and comments. Best regards. Nicolas Commented Nov 5, 2016 at 10:11
  • Please be sure to mark the accepted answer as correct by marking the check mark by the answer that solved your problem. Commented Nov 5, 2016 at 16:42

2 Answers 2

1

If I understand correctly, an array of objects would work well. Since you have a set number of textfields I assume that you also have a set number of details that you want to display in them. If that is the case, this solution should work fine.

arr:Array = [{_name:"ERLQ1",ans1:"N09°02.61 / E100°49.11",ans2:"ErawanLq"},
             {_name:"ERLQ2",ans1:"question 2 answer 1",ans2:"ques2ans1"}];

So, I don't really "get" your application, but if it were some sort of a quiz, you'd have a new array element for each question, and that element has a name, and two answers. Easy to modify it to grab answers from an answer pool. Now to find the element in the array that has ._name == "ERLQ1" you will need to loop through all the elements and return the one that has the ._name property that matches your search. Here is an example function:

private function matchName(arr:Array, term:String):int{
    for (var i:int = 0; i < arr.length; i++){
        if (arr[i]._name == term){
            return i;
        }
    }
    return -1;
}

This function will return the array index number of the matching term. If no match exists, it returns -1. So you could use it like this (pseudocode):

// on submit search{
    // find the index number in the array of the element that matches the search term
    var ind:int = matchName(arr, searchTerm);

    // assign the textfield texts to the corresponding associated values
    textBox1:text = arr[ind]._name;
    textBox2:text = arr[ind].ans1;
    textBox3:text = arr[ind].ans2;
}
Sign up to request clarification or add additional context in comments.

Comments

0

I perhaps misunderstood (because of my English), but :

import flash.text.TextField;
import flash.text.TextFieldAutoSize;
var ERLQ1:Array = ["ERLQ1",  "N09°02.61 / E100°49.11", "ErawanLq"];
var Txt1 : TextField = new TextField();
Txt1.autoSize=TextFieldAutoSize.CENTER;
Txt1.type = TextFieldType.INPUT;
Txt1.border = true;
var Txt2 : TextField = new TextField();
Txt2.autoSize=TextFieldAutoSize.CENTER;
Txt2.type = TextFieldType.INPUT;
Txt2.border = true;
var Txt3 : TextField = new TextField();
Txt3.autoSize=TextFieldAutoSize.CENTER;
Txt3.type = TextFieldType.INPUT;
Txt3.border = true;
addChild(Txt1);
addChild(Txt2);
addChild(Txt3);
Txt1.x = 20, y =40;
Txt2.x = 180, y =40;
Txt1.x = 300, y =40;
Txt1.text = ERLQ1[0];    // is now : first part of the array as main reference (String(ERLQ1[0]).
Txt2.text = ERLQ1[1];    // is now : String(ERLQ1[1]);
Txt3.text = ERLQ1[2];    // is now : String(ERLQ1[2]);

This will display 3 TextFiels as input text like this : enter image description here

If I misunderstood your question, please tell me more about what You expect! Best regards. Nicolas

3 Comments

Thanks for the quick answer and sorry if I was not clear enough. I was OK with the creation of the fields, which is why I did not include in the code. Basically what I want is AS3 to search the Array and display the answers in the different textfields. Before clicking the search button, customer type "ERLQ1 in the Input textbox. After click, AS3 will display the extra details of ERLQ1 in different textboxes. From the answer, my problem is to get ERLQ[0] beside Txt1.text. ERLQ1 needs to come from the Input box. I tried to concatenate ERLQ1 + [0] but it did not work. Thanks again. Andre.
you should add that comment to your original post :)
Thanks Neal. Really appreciate it. Your way of writing the Array makes it work. That was the part I was missing. As I said, it is the first time I write in a forum and obviously, I have things to learn. Thanks as well Nicolas for taking the time to help. I can keep moving forward with my project. Regards. Andre

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.