# Loading txt file to variable

**URL:** <https://forum.kirupa.com/t/loading-txt-file-to-variable/20722>\
**Category:** flash\
**Created:** [May 12, 2003, 7:45pm UTC](https://forum.kirupa.com/t/loading-txt-file-to-variable/20722 "2003-05-12T19:45:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sorcerer](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@Sorcerer](https://forum.kirupa.com/u/Sorcerer)\
**Post date:** [May 12, 2003, 7:45pm UTC](https://forum.kirupa.com/t/loading-txt-file-to-variable/20722/1 "2003-05-12T19:45:40Z")

</div>

I am having some trouble loading an html formatted text file as a variable and displaying it in a dynamic text box.

here is the code i used to load the variable

```auto

newsheadlines = new loadVars();
newsheadlines.load("headlines.txt");

```

I then have a dynamic text box set to format as html and to have a border with \_root.newsheadlines as it’s variable. When I run my flash movie it displays the contents of my txt file but displays it using html code for symbols instead of displaying as html. For example each headline is bolded

```php
<b> it displays it as %3Cb%3E

```

Anyone run into this problem before, I know I’m probably overlooking something simple.

One other question, is it possible to make it so flash doesn’t add a blank line where a carriage return is when loading dynamic text?

---

<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:** [May 12, 2003, 8:42pm UTC](https://forum.kirupa.com/t/loading-txt-file-to-variable/20722/2 "2003-05-12T20:42:32Z")

</div>

try this:

```auto
myTextField.htmlText = unescape(newsheadlines.someVariable);

```

🙂

> _Originally posted by Sorcerer_  
> **One other question, is it possible to make it so flash doesn’t add a blank line where a carriage return is when loading dynamic text?**

yeah… add an **&** at the end of each variable. 😉

ie.  
myText1=some text here&  
myText2=some text there&

---

<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:** [May 12, 2003, 9:46pm UTC](https://forum.kirupa.com/t/loading-txt-file-to-variable/20722/3 "2003-05-12T21:46:42Z")

</div>

I found one of my problems, inside my text file i have links to a php page which is bing passed variables which use & in the url. Is there a way to either escape these characters so flash doesn’t interpet them as variables?

Is it possible to load the entire text file into a variable without having to declare a variable within the text file? The file is generated by a script and it would be much easier if I didn’t have to worry about each headline being declared as a varaible in flash.

---

<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:** [May 12, 2003, 11:44pm UTC](https://forum.kirupa.com/t/loading-txt-file-to-variable/20722/4 "2003-05-12T23:44:32Z")

</div>

first question:  
you have the answer right there in your post… escape those characters. use **%26** instead of &. 😉

second question:  
if i understood… you’ll need to unescape the .txt and if you’re using an onLoad handler, you’ll have to remove it from the string.

something like this should work:

```auto
var lv = new LoadVars();
lv.onLoad = function() {
var tmp = unescape(this);
trace(tmp.substr(0, tmp.lastIndexOf("=&")));
}
lv.load("someText.txt");

```

😉
