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);
}
}
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);
}
}
Copy link to clipboard
Copied
assuming that's all on the same timeline (ie, same scope), use
this['REDqestText'+i].text
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.
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.
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()
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.
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
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);
}
}
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
Copy link to clipboard
Copied
But I cant get text from theese text fields
Copy link to clipboard
Copied
and yes this line trigering the error.:/
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.
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.
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);
}
}
Copy link to clipboard
Copied
All in one frame and why i get this error i dont know,
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);
}
}
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!!!!!!!!!!
Copy link to clipboard
Copied
you're welcome.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)