0
votes

First I use URLRequest to read a txt file contain multiple lines of String

var urlRequest:URLRequest = new URLRequest("listOfJsonFile.txt");

and I had created a array

private var listOfJson:Array = new Array();

Then I split each string into array

var loader:URLLoader = URLLoader(event.target);

listOfJson = loader.data.split(/\n/);

trace(listOfJson[0]); // return XXX.Json

Question:

How can I do:

var urlRequest:URLRequest = new URLRequest(listOfJson[0]);

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error.

I have try create a temp var string or cast the element to String().

I did: var urlRequest:URLRequest = new URLRequest("XXX.json"); and it work.

1
Can you post what the file contents looks like?Aaron Beall

1 Answers

0
votes

Maybe your text file contains \r (carriage return) characters as well as \n (newlines)? That depends on your operating system. When you split on \n characters only, those CR characters remain part of the file name you try to load, and the file XXX.json\r doesn't likely exist.

So use split("\r\n") and see if that helps.
If that doesn't help, it may even be the other way round (I keep forgetting the actual order: split("\n\r")).