Load text from outside text file

load text from outside text file

Page 1 of 1

2 Replies - 8313 Views - Last Post: 11 March 2008 - 11:19 PM

#1 inf4my   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 19-November 07

Load text from outside text file

Post icon  Posted 11 March 2008 - 09:35 AM

I am trying to load text dynamically from a text file into a field right now my code displays
[object URLLoader] in the text field
and displays the warning Warning: 1090: Migration issue: The onload event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'load', callback_handler).



var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
myLoader.load(new URLRequest("text/bio.txt"));
 myLoader.addEventListener(Event.COMPLETE, onload);
	function onload(ev:Event){
		trace ("Data loaded");
	}
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
var speech:String= String(myLoader);

contents.text = speech;
contents.multiline = true;
contents.wordWrap = true;


Is This A Good Question/Topic? 0
  • +

Replies To: Load text from outside text file

#2 thehat   User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Load text from outside text file

Posted 11 March 2008 - 10:14 AM

Hi inf4my,

There are a three things wrong that I can see:

1. Your function name is a reserved word, changing it gets rid of your compiler error.
2. You are assigning to speech the data type of myLoader, not the data you hope to return.
3. You can't assign text to the text box until the data has come back from your URLLoader, so that needs to be inside the function.

This amended version of your code should work:

var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
myLoader.load(new URLRequest("text/bio.txt"));
myLoader.addEventListener(Event.COMPLETE, onloader);

function onloader(ev:Event){
	contents.text = String(myLoader.data);
}

contents.multiline = true;
contents.wordWrap = true;


Hope that helps :)

Edit: it helps if I actually make all the changes in the code... :rolleyes:

This post has been edited by thehat: 11 March 2008 - 10:43 AM

Was This Post Helpful? 0
  • +
  • -

#3 inf4my   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 19-November 07

Re: Load text from outside text file

Posted 11 March 2008 - 11:19 PM

Thanks A lot I had been scouring the internet for hours and could not find a single place that actually had the exact solution I needed but claimed to. Your Post was informative and showed the correct code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1