Loading External Text Files into Flash MX

[font=verdana, arial, helvetica][size=2]Hi Guy’s and Gall’s

I have a couple problems, i imagine probably easily fixed, but over my head

Number 1…

My flash movie loads an external text file on loading, then display’s it in another scene in a scrolling box.
The problem is all the line breaks, it seems to add 2 for every 1, is that to do with the text file? or have i missed something in flash? can i remove them with action script?

Number 2…

The Flash movie doesn’t reload the text file every time you oven the page, it seems to open a ‘cached’ version, can i do anything about this?

www.bexinoz.com

Thanks in anticipation of any help you guys can give me!

Andy[/size][/font]

Regarding the caching, the usual trick is to make sure that the URL changes slightly each time to fool the browser. Do this with a querystring. It doesn’t have to do anything. You could generate it randomly with JavaScript, so that your Flash page URL is maybe something like:

http://www.yoursite.com/flash.html?14526

As for the two line breaks between paragraphs. Its because windows newlines are \r
and so flash interprets that as two line breaks.

I have written quite a bit on this subject over at actionscript.org


function loadText(txtFile, target) {
 myVars = new LoadVars();
 myVars.load(txtFile);
 myVars.onData = function(raw) {
  var tmpText = "";
  if (raw.indexOf("\\r\
") > -1) {
	tmpText = raw.split("\\r\
").join("\
");
  }
  else tmpText = raw;
  target.text = tmpText;
 }
}
loadText("myText.txt", _root.myText);

So this is my method and works quite nice. Keep in mind you need to have a text file that is just raw text, for instance


Yo I am some text with windows line breaks, yes I am Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
v
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
Yo I am some text with windows line breaks, yes I am 
v
 

So there you go, this is my method for taking care of that problem.

I currently have a dynamic textbox with an actionscript input of:

t = "Text1
Text2

";
text = t;

What I would like to do (keep in mind this box is linked with a scroll bar but it should not matter) is have Text1, Text2, etc. called from a text file called calendar.txt using the code above where I believe I could just list event titles in an organized way and have flash separate the lines for me.

How can I make this work?

hi
try this way

t = Text1 + "
" + Text2 + "

";
text = t;

hey is there a as3 version of this floating around?

function loadText(txtFile, target) {
	myVars = new LoadVars();
	myVars.load(txtFile);
	myVars.onData = function(raw) {
		var tmpText = "";
		if (raw.indexOf("\\r\
")>-1) {
			tmpText = raw.split("\\r\
").join("\
");
		} else {
			tmpText = raw;
		}
		target.text = tmpText;
		//trace(tmpText)
		myfield.htmlText = tmpText;
	};
}

loadText("affiliates.txt",_root.mycopyVar);