0

I am using the example code in flash. I want a single variable and not the whole text. I have a dynamic textfield called OUTPUT on the stage.

var fl_TextLoader:URLLoader = new URLLoader();
var fl_TextURLRequest:URLRequest = new URLRequest("http://www.testing.com/Christmas.txt");

fl_TextLoader.addEventListener(Event.COMPLETE, fl_CompleteHandler);

function fl_CompleteHandler(event:Event):void
{
    var textData:String = new String(fl_TextLoader.data);
    OUTPUT.text = textData;
}

fl_TextLoader.load(fl_TextURLRequest);

The Christmas text file contents:

Var1=Jesus&Var2=Mary&Var3=Christmas

The OUTPUT comes out with the whole string. How do I get the url parameter values separately?

Like OUTPUT.text = textData.Var1; (<--- But this does not work.)

NikiC
  • 100,734
  • 37
  • 191
  • 225
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137

1 Answers1

1

The .data property is just a string, the raw data returned by the HTTP call, so you will have to parse the variable-value pairs, either using simple .split() on the strings or using the URLVariables object, that can do the parsing for you:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html#decode()

Lars Blåsjö
  • 6,118
  • 2
  • 19
  • 23
  • 1
    This guy is right, do this: `var vars:URLVariables = new URLVariables(fl_TextLoader.data); trace(vars.Var2); //Traces "Mary"` – ToddBFisher Jan 07 '12 at 04:33