Loading txt file to variable

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


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

<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?

try this:

myTextField.htmlText = unescape(newsheadlines.someVariable);

:slight_smile:

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. :wink:

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

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.

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

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:

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

:wink: