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

Get text from input TextFields by instance name

Explorer ,
Feb 14, 2019 Feb 14, 2019

Copy link to clipboard

Copied

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);

    }

}

TOPICS
ActionScript

Views

643

Translate

Translate

Report

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

Community Expert , Feb 16, 2019 Feb 16, 2019

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);

    }

}

Votes

Translate

Translate
Community Expert ,
Feb 15, 2019 Feb 15, 2019

Copy link to clipboard

Copied

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

this['REDqestText'+i].text

Votes

Translate

Translate

Report

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
Explorer ,
Feb 15, 2019 Feb 15, 2019

Copy link to clipboard

Copied

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

But if I write something new i get old string.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 15, 2019 Feb 15, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Explorer ,
Feb 15, 2019 Feb 15, 2019

Copy link to clipboard

Copied

Full code:

function show_RED_questions(){

    while (window.numChildren > 0) {

        window.removeChildAt(0);

    }

    trace("window clear");

    stage.addChild(window);

    var position2_y:Number = 44;

    var tarpas:int;

    tarpas = 220 / (REDquestionsLineArray.length-1);

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

        if(REDquestionsLine==null){

            //nedaryk nieko

        }else{

            trace("----++++++++++-----");

            var REDqText:TextField = new TextField();

            REDqText.name = 'REDqestText' + i;

            window.addChild(REDqText);

            var myFormat2:TextFormat = new TextFormat();

            myFormat2.size = 14;

            REDqText.defaultTextFormat = myFormat2;

           

            REDqText.height = 20;

            REDqText.type = "input";

            REDqText.border = true;

            REDqText.x = 292;

           

            REDqText.width = 600;

            REDqText.y = position2_y;

       

            REDqText.text = String(REDquestionsLine);

            position2_y = position2_y + tarpas;

            if(i == REDquestionsLineArray.length-1){

                window.addChild(save_button);

                save_button.x = 677;

                save_button.y = 344;

                save_button.addEventListener(MouseEvent.CLICK, save_REG_questions);

            }

        }

    }

}

var REDquestLine = [];

var saveREDquestionsLine:String

function save_REG_questions(e:MouseEvent):void{

    saveREDquestionsLine = "";

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

        REDquestLine = this['REDqestText' + i].text;

        saveREDquestionsLine = saveREDquestionsLine + REDquestLine + "|";

        trace(saveREDquestionsLine);

    }

}

Oh SORRy I dont get nothing just error;

TypeError: Error #1010: A term is undefined and has no properties.

    at apklausa_fla::MainTimeline/save_REG_questions()

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 15, 2019 Feb 15, 2019

Copy link to clipboard

Copied

if that else branch is executing, you have a problem in your logic.  you probably want that if-statement in your other function, too.

you can confirm:

click file>publish>tick 'permit debugging'.  retest.

the problematic line of code will be in the error message.  if it's   REDquestLine = this['REDqestText' + i].text; and the i's match in the else-branch with the first error message, you've confirmed it.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

First unctions work perfect for me and i get in this case 5 Text fields with instance names REDquestText0 REDquestText1 and etc. With second function I want to get all 5 strings from textfields in one String. But it not works as I want. I can get for examle TextField|TextField|TextField|TextField|TextField| but not the text in theese textfields. It sound simple thing but its so dificult to get. With permit Debugging I get same error and it not works

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

1. is REDquestLine = this['REDqestText' + i].text; triggering the error?

2. what values of i execute in the if-branch *

3. what's the last value of i traced just before the error? **

*

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

        if(REDquestionsLine==null){

            //nedaryk nieko

trace(i)

        }else{

            trace("----++++++++++-----");

            var REDqText:TextField = new TextField();

            REDqText.name = 'REDqestText' + i;

**

function save_REG_questions(e:MouseEvent):void{

    saveREDquestionsLine = "";

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

trace(i)

       REDquestLine = this['REDqestText' + i].text;

        saveREDquestionsLine = saveREDquestionsLine + REDquestLine + "|";

        trace(saveREDquestionsLine);

    }

}

Votes

Translate

Translate

Report

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
Explorer ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

*

0

1

2

3

4

**

0

1

2

3

4

I dont understand where is the problem.

This is Im getting

Be pavadinimo.png

Votes

Translate

Translate

Report

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
Explorer ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

But I cant get text from theese text fields

Votes

Translate

Translate

Report

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
Explorer ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

and yes this line trigering the error.:/

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

your trace results don't make sense if you put those trace statements in the correct locations.

if you want to hire me to fix your problem, let me know.  if you want free via the forums you should follow my suggestions.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

Everything makes no sense beouse verything looks ok and should work, why not workng i dont know:(((

I did everythink like you said and i get same error.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

import flash.display.MovieClip;
import flash.utils.Endian;
import flash.text.TextField;

var window:MovieClip = new MovieClip;
stage.addChild(window);

var lt_button:ltbutton = new ltbutton;
lt_button.x = 289;
lt_button.y = 7;
var en_button:enbutton = new enbutton;
en_button.x = 352;
en_button.y = 7;
var ru_button:rubutton = new rubutton;
ru_button.x = 416;
ru_button.y = 7;

redaguotiklausimus.addEventListener(MouseEvent.CLICK, add_lang_buttons);

function add_lang_buttons(e:MouseEvent):void{
    window.addChild(lt_button);
    lt_button.addEventListener(MouseEvent.CLICK, add_lt_questions);
    window.addChild(en_button);
    en_button.addEventListener(MouseEvent.CLICK, add_en_questions);
    window.addChild(ru_button);
    ru_button.addEventListener(MouseEvent.CLICK, add_ru_questions);
}

var link:String;

function add_lt_questions(e:MouseEvent):void{
    link = "LT";
    load_RED_questions();
}

function add_en_questions(e:MouseEvent):void{
    link = "EN";
    load_RED_questions();
}

function add_ru_questions(e:MouseEvent):void{
    link = "RU";
    load_RED_questions();
}

var REDquestionsLoader:URLLoader;
var REDquestionsArray:Array = new Array();
var REDquestionsLineArray:Array = new Array();

function load_RED_questions(e:MouseEvent = null):void{
    REDquestionsLoader = new URLLoader;   
    if(link == "LT"){
        REDquestionsLoader.load(new URLRequest("LTquestions.txt"));
    }
    if(link == "EN"){
        REDquestionsLoader.load(new URLRequest("http://www.demetra.lt/apklausa/ENquestions.txt"));
    }
    if(link == "RU"){
        REDquestionsLoader.load(new URLRequest("http://www.demetra.lt/apklausa/RUquestions.txt"));
    }
    REDquestionsLoader.addEventListener(Event.COMPLETE, REDquestions_Loaded);
}

var REDquestionsLine = [];

function REDquestions_Loaded(event: Event): void {
    REDquestionsArray = event.target.data.split("\n");
    REDquestionsLineArray = REDquestionsArray[0].split("|");
    trace(REDquestionsLineArray.length);
    for (i = 0; i < REDquestionsLineArray.length; ++i) {
        REDquestionsLine = String(REDquestionsLineArray);
        //trace(hello_line);   
        if(i == REDquestionsLineArray.length-1){
            show_RED_questions();
        }
    }
}
var save_button:issaugotibutton = new issaugotibutton;
var REDqText:TextField = new TextField();
function show_RED_questions(){
    while (window.numChildren > 0) {
        window.removeChildAt(0);
    }
    trace("window clear");
    stage.addChild(window);
    var position2_y:Number = 44;
    var tarpas:int;
    tarpas = 220 / (REDquestionsLineArray.length-1);
    for (i = 0; i < REDquestionsLineArray.length; ++i) {
            trace(i);
           
            REDqText = new TextField;
            stage.addChild(REDqText);
            REDqText.name = "text" + i;
            trace(stage.getChildByName("text" + ).name);
            var myFormat2:TextFormat = new TextFormat();
            myFormat2.size = 14;
            REDqText.defaultTextFormat = myFormat2;
           
            REDqText.height = 20;

            REDqText.type = "input";
            REDqText.border = true;
            REDqText.x = 292;
           
            REDqText.width = 600;
            REDqText.y = position2_y;
       
            REDqText.text = String(REDquestionsLine);
            position2_y = position2_y + tarpas;
            if(i == REDquestionsLineArray.length-1){
                stage.addChild(save_button);
                save_button.x = 677;
                save_button.y = 344;
                save_button.addEventListener(MouseEvent.CLICK, save_REG_questions)
            }
        }
    }


var REDquestLine = [];

var saveREDquestionsLine:String;

function save_REG_questions(e:MouseEvent):void{
    saveREDquestionsLine = "";   
    trace("---");
    for (i = 0; i < REDquestionsLineArray.length; ++i) {
        trace(i);
        trace(this["text" + i].text);
        saveREDquestionsLine = saveREDquestionsLine + REDquestLine + "|";
        trace(saveREDquestionsLine);
    }
}

Votes

Translate

Translate

Report

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
Explorer ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

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);

    }

}

Votes

Translate

Translate

Report

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
Explorer ,
Feb 17, 2019 Feb 17, 2019

Copy link to clipboard

Copied

TypeError: Error #1009: Cannot access a property or method of a null object reference. Its something crazzy ... trace(stage.getChildByName("text" + ).name); im geting : text0 text1 text2 text3 text4 trace(TextField(this.getChildByName("text" + i)).text); im getting error TypeError: Error #1009: Cannot access a property or method of a null object reference so i use STAGE not THIS and it works! THANK YOU!!!!!!!!!!

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 17, 2019 Feb 17, 2019

Copy link to clipboard

Copied

LATEST

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Votes

Translate

Translate

Report

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