0

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

bouldo
  • 1
  • 3

2 Answers2

0

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("=");
Arkady
  • 1,178
  • 14
  • 35
  • Thanks for the response - almost what I was looking for - the prob is the entries which begin with '#' - thanks. – bouldo Aug 21 '12 at 22:57
0

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

mahatmanich
  • 10,791
  • 5
  • 63
  • 82
  • there is no scripting language available - swfobject cannot be used as the file is launched by stagecraft (fp3.1) - cheers – bouldo Aug 22 '12 at 01:10