tags:

views:

26

answers:

1
// This is AS2 Coding

this.createEmptyMovieClip("some_mc", 1);
some_mc.loadVariables("external.txt");
some_mc.onEnterFrame = function() {
 if (this.done == "yes") {
  // the variables have finished loading
  trace("**\nfinished loading\n**\nthe variables are:");
  trace(this.fName); // outputs nuno 
  trace(this.lName); // outputs mira 
  trace(this.age); // outputs 24 
  // delete the method to end the loop
  delete this.onEnterFrame;
 }  else  { 
  // not loaded yet
  trace("**\nstill loading\n**");
 }
};

//I want AS3 Coding

//in the text file external.txt data:

&fName=nuno& 
&lName=mira& 
&age=24&
A: 

So what are the chances that this question: http://stackoverflow.com/questions/909409/how-to-read-text-file-external-txt-in-as3 was also submitted by you? Double question and profile, sneaky... You should close one of them.

And in any case the code you have there is not exactly best practice, and neither is the format in the text file. I would suggest using xml instead, but in the other question you seem to insist on using the near standard text format (normally it would be fName=nuno&lName=mira&age=24).

Anyway, to do it you first need to load in the text with an URLLoader, the example should give you all you need.

Then you need to parse the text, I would suggest Regex, the example should give you most of what you need. You should be able to parse it with /&(.+)=(.+)&/g (check this on capturing substrings), where the first substring is the name and the second the value.

Then you can finally run through the arrays you end up with and put everything into a Dictionary so you can access the values by name.

Lillemanden