tags:

views:

30

answers:

1

Which function can I use to get the content of a plain text file?

I can just read "value=32" as a variable or file in xml format now, but the file from vendor contains only the value "32".

A: 

Oops: Only now did I notice that you are on AS2: use LoadVars instead. (Got this from here)

var ldr = new LoadVars();
ldr.onData  = function (result:String) 
{
  if (success) 
  {
    trace("loaded " + result);
  }
  else
  {
    trace ("Error loading");
  }
} 
ldr.load("fileurl.txt");


The following applies only to AS3:

If the file is at your server (or a server that allows your swf to access it with a crossdomain.xml), you can load it using URLLoader.

var ldr:URLLoader = new URLLoader();
ldr.addEventListener(Event.COMPLETE, onLoad);
ldr.load(new URLRequest("fileurl.text"));

function onLoad(e:Event):void
{
  var loadedText:String = URLLoader(e.target).data;
  var value:Number = Number(loadedText);
}
Amarghosh
Given that OP states he is using AS2, this isn't a good answer.
spender
@spender Added the AS2 code.
Amarghosh