ActionScript 3.0 - where’s my LoadVars?
28 11 2007I recently got a question about what the ActionScript 3.0 equivalent is of the LoadVars sendAndLoad method. It may look like a lot more typing (and it is) but the whole implementation is very clean by separating out the request, loader and variables which you can only benefit from in the long run.
import flash.events.Event;
import flash.net.*;
var myRequest:URLRequest = new URLRequest("http://www.myserver.com/myscript.php");
var myLoader:URLLoader = new URLLoader();
var myVariables:URLVariables = new URLVariables();
myVariables.firstProperty = "first";
myVariables.secondProperty = "second";
myRequest.method = URLRequestMethod.GET;
myRequest.data = myVariables;
function onLoaded(evt:Event):void {
trace("here we get the data back: "+myLoader.data);
}
myLoader.addEventListener(Event.COMPLETE, onLoaded);
myLoader.load(myRequest);
What happens in the code above is we set up a URLRequest instance that points to the server side resource you want to target. Next an instance of the URLLoader class is instantiated and we assign an instance of the URLVariables class to its data property.
Categories : Flash, Flex






