Skip to main content
dalvydasv27776233
Inspiring
February 14, 2019
Answered

Get text from input TextFields by instance name

  • February 14, 2019
  • 1 reply
  • 1237 views

Hey, I have problem.. I know its simply thing, but 2 hours I cant do this:

for (var i = 0; i < REDquestionsLineArray.length; ++i) {

            var REDqText:TextField = new TextField();

            REDqText.name = "REDqestText" + ;

            window.addChild(REDqText);

            REDqText.text = String(REDquestionsLine);

            trace(REDqText.name);

            trace(REDqText.text);

}

var REDquestLine = [];

var saveREDquestionsLine:String

function save_REG_questions(e:MouseEvent):void{

    saveREDquestionsLine = "";

    for (var i = 0; i < REDquestionsLineArray.length; ++i) {

        REDquestLine = HOW TO GET TEXT STRVING FROM THEESE ("REDqestText" + ;)INPUT TEXTFIELDS?

        trace(REDquestLine);

    }

}

This topic has been closed for replies.
Correct answer kglad

All in one frame and why i get this error i dont know,


use:

function save_REG_questions(e:MouseEvent):void{

    saveREDquestionsLine = "";   

    for (i = 0; i < REDquestionsLineArray.length; ++i) {

    

        trace(TextField(this.getChildByName("text" + i)).text);

        saveREDquestionsLine = saveREDquestionsLine + REDquestLine + "|";

        trace(saveREDquestionsLine);

    }

}

1 reply

kglad
Community Expert
Community Expert
February 15, 2019

assuming that's all on the same timeline (ie, same scope), use

this['REDqestText'+i].text

dalvydasv27776233
Inspiring
February 15, 2019

It works, but Im getting old text. same as i set before.:\

But if I write something new i get old string.

kglad
Community Expert
Community Expert
February 15, 2019

then you're setting i incorrectly, calling that code at the incorrect time or overwriting textfield names.  use the trace function to debug.