I'm not very used to as3. I want to convert some data from txt file to actual as3 object.
- How do I load text at "/data/file.txt"
- How do I find words in the text? For example: I want to find 'frame' and retrieve every symbol serie (separated with space) and add it into an array/table.
1.
It depends. If the file's on the client machine, you can only load it if you're using AIR (Flash Player, which runs out of the browser, does not support this). Use
FileStream.readUTFBytes()
, like this:A couple of notes about this: If I'm not mistaken, at least unless you find some sort of special trick to do this, the File's
nativePath
property needs to be set to either an absolute path or, if it is a relative path, it needs to be within the same directory as the program (it can be in a subdirectory). This is probably a security thing Adobe intentionally implemented. Also setting thenativePath
(either explicitly or through the constructor) can raise an error, so the outer try...catch block is important too.If you're loading the file off a server through a URL, you can use either Flash Player or AIR. Just use a
URLLoader
instead:2.
I'm not sure I follow what you're wanting to do with the text, but you can split a
String
into an array. If you want to find the word "frame", and if you care about case in this instance, you can do something like the following:For loading text file you will need
URLLoader
, for searching, String methodsWorking example:
Content of file is:
Result will be all text from the word commodo