# FMX -Loading external text into variable

**URL:** <https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798>\
**Category:** flash\
**Created:** [August 6, 2003, 6:50pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798 "2003-08-06T18:50:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![borispc](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@borispc](https://forum.kirupa.com/u/borispc)\
**Post date:** [August 6, 2003, 6:50pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/1 "2003-08-06T18:50:59Z")

</div>

Hi!  
What is the best method to load external text into a variable, not directly into a text field but a variable that is going to be used later. thanx.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 6:55pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/2 "2003-08-06T18:55:35Z")

</div>

[AS]var loadText = new loadVars();  
loadText.load(“textfile.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
myVar = this.textVar;  
} else {  
trace (“Error loading data”);  
}  
};[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 6:56pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/3 "2003-08-06T18:56:49Z")

</div>

let me try it again…but that is exactly the method I was using and it didn’t work…I guess I did something wrong…:S let me check  
thanx claudio

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:08pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/4 "2003-08-06T19:08:52Z")

</div>

ok so here is what I have:  
My external text file is called data.txt and has a variable named “name”:

var loadText = new loadVars();  
loadText.load(“data.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
myVar = this.name;  
trace(myVar);//this one traces the name variable in the text field fine  
} else {  
trace(“Error loading data”);  
}  
}  
trace(myVar);//this one returns undefined  
//Then I wanted to assign that value to my\_str:

my\_str = myVar;

so I get the name and undefined in the output window… :d:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:12pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/5 "2003-08-06T19:12:46Z")

</div>

[AS]var loadText = new loadVars();  
loadText.load(“data.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
myVar = this.name;  
my\_str = myVar;//you have to do this after the txt file is loaded  
trace(mystr);  
} else {  
trace(“Error loading data”);  
}  
};[/AS]

[edit]and theres no point of using my\_str = myVar; you should use my\_str = this.name;[/edit]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:15pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/6 "2003-08-06T19:15:57Z")

</div>

I had tried that but same thing happens:

var loadText = new loadVars();  
loadText.load(“data.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
myVar = this.name;  
my\_str = myVar;  
trace(my\_str);//this one’s fine  
} else {  
trace(“Error loading data”);  
}  
}  
trace(my\_str);//this one is undefined…I need to used it right here outside the function…it’s undefined…making the variable global didn’t work either

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:18pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/7 "2003-08-06T19:18:43Z")

</div>

It makes more sense like this but still doesn’t work:  
var loadText = new loadVars();  
loadText.load(“data.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
my\_str = this.name;  
trace(my\_str);//right value  
} else {  
trace(“Error loading data”);  
}  
}  
trace(my\_str);//undefined

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:20pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/8 "2003-08-06T19:20:41Z")

</div>

I’m not sure, but I think load has to come after onLoad, and that my\_str has to be put in \_root.

[AS]  
var loadText = new loadVars();  
loadText.onLoad = function(success) {  
if (success) {  
myVar = this.name;  
\_root.my\_str = myVar;  
trace(\_root.my\_str);//this one’s fine  
} else {  
trace(“Error loading data”);  
}  
}  
loadText.load(“data.txt”);  
trace(\_root.my\_str)  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:24pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/9 "2003-08-06T19:24:16Z")

</div>

that doesn’t make sense to me…  
if you don’t load it at the beginning how is flash supposed to pick up the variables of the text file unless it’s loaded?  
:p:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:26pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/10 "2003-08-06T19:26:02Z")

</div>

I think, but I’m not sure, that onLoad defines what Flash must do when it is loaded, and that load actually loads it. So first tell what to do, then load, instead of load and then tell what to do.

Have you tried putting it in root ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:28pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/11 "2003-08-06T19:28:42Z")

</div>

May i ask what you want to do?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 7:50pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/12 "2003-08-06T19:50:59Z")

</div>

ok…what I want to do is the following:  
I want to load an external text file and format that in flash in consecutive columns. The column part is already solved, all I need is to have the text in a variable called my\_str. So all I need is to load that text into my\_str.  
Another thing…how do I format that text (external text) if I’m creating the text fields on the fly with the method: createTextField (instanceName, depth, x, y, width, height)??? I want to be able to control line breaks specially (\<br\>), so how do I assign the htmlText property to that field created with AS?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 8:03pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/13 "2003-08-06T20:03:36Z")

</div>

Can you post your fla?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 8:17pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/14 "2003-08-06T20:17:40Z")

</div>

next message is the text field

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 8:18pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/15 "2003-08-06T20:18:31Z")

</div>

here is the text…you can paste a big text file in it if you want to see the column thing working

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 8:20pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/16 "2003-08-06T20:20:16Z")

</div>

Unexpected File Format.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 8:21pm UTC](https://forum.kirupa.com/t/fmx-loading-external-text-into-variable/27798/17 "2003-08-06T20:21:39Z")

</div>

hope this one is good
