PDA

View Full Version : Creating several TextFields with recursion?



Danneman
May 4th, 2004, 01:16 PM
Hi,

Im trying to create several TextFields using function recursion.



arr_HelpRubrik = new Array();
arr_HelpRubrik = [1, 2, 3, 4];

var x_pos = 10;
var y_pos = 10;

fn_LoadHelpRubrik(arr_HelpRubrik[0]);

function fn_LoadHelpRubrik(i){

var txt_Rubrik = new LoadVars();
var txt_Path = "HELP_" + arr_HelpRubrik[i] + ".txt";
txt_Rubrik.load(txt_Path);
txt_Rubrik.onLoad = function(success) {
if(success){
_root.createTextField("txt_Rubrik_" + arr_HelpRubrik[i], 1, x_pos, y_pos, 1000, 16);
_root["txt_Rubrik_" + arr_HelpRubrik[i]].htmlText = this.TEXT;

y_pos += 20;
i ++;
fn_LoadHelpRubrik(arr_HelpRubrik[i]);
}
}
}


What it does is look for the existence of a textfile (HELP_i.txt) and if it exists, create a TextField into which it is supposed to output the contents of that file. So Im supposed to have as many textfrelds as there are textfiles in the end, all situated in a kolumn.

Well, what actually happens is that every textfield is correctly created, but will close as soon as the next one is created. So I end up with only one textfield.

Anybody know how to solve this?
Thanks

kode
May 4th, 2004, 03:58 PM
You can't have 2+ objects at the same depth, assign a different depth to each text field...

_root.createTextField("txt_Rubrik_"+arr_HelpRubrik[i], i, x_pos, y_pos, 1000, 16);

Danneman
May 5th, 2004, 02:36 AM
Oh, ok. Thanks a lot, kode - works fine now :)

kode
May 5th, 2004, 02:55 AM
You're welcome. ;)