parse data from text file - flash as2

1.5k Views Asked by At

I have a text file that I need to retrieve a name/value pair from that looks like this


#Hostname
hostname=6544

value1=12
value2=78978


Can anyone tell me how to parse this so I can reference the variable 'hostname' value.

This has to be in Actionscript 2 - as the project is for flashlite 3.1

Thanks heaps

2

There are 2 best solutions below

1
On

Something like this:

import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;

var files:File = File.appResourceDirectory;
files = files.resolve("mycommands.txt");

var fs:FileStream = new FileStream();
fs.open(files, FileMode.READ);
var content:String = fs.readUTFBytes(fs.bytesAvailable);

var pair:Array = content.split("=");
1
On

Have a look at swfobject it lets you pass variables to your flash file. You can pass the variables with any scripting language you may be using.

Otherwise, there are tons of tutorials on google on how to read in a text file with as2.

e.g. here

further look for loadVariables and LoadVars functions in as2