ActionScript - Post request data in AS3

This simple example shows how to use the URLLoader and URLRequest class in actionscript 3 to post data to a server:

var loader : URLLoader = new URLLoader();  
var request : URLRequest = new URLRequest("/index.php");  
 
request.method = URLRequestMethod.POST;  
var variables : URLVariables = new URLVariables();  
variables.key1 = "value1";  
variables.key2 = "value2";  
request.data = variables;  
 
//  Handlers  
loader.addEventListener(Event.COMPLETE, on_complete);  
loader.load(request);  
private function on_complete(e : Event):void{  
       // whatever 
 }

Another example from the documentation:

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.*;
 
    public class URLRequestExample extends Sprite {
 
        public function URLRequestExample() {
            var loader:URLLoader = new URLLoader();
            configureListeners(loader);
 
            var request:URLRequest = new URLRequest("XMLFile.xml");
            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
        }
 
        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }
 
        private function completeHandler(event:Event):void {
            var loader:URLLoader = URLLoader(event.target);
            trace("completeHandler: " + loader.data);
        }
 
        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }
 
        private function progressHandler(event:ProgressEvent):void {
            trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
        }
 
        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }
 
        private function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }
 
        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }
    }
}
Reply:
 
 
 
 
Nice.:)
I have this code how can i convert to as3?

mcPaypal.onRelease = function():Void{
//send variables to paypal

//CONSTANTS
lvSend.cmd = "_cart";
lvSend.upload = "1";

var j:Number = 1;
for (var i in aItem) {
if(aItem[i].quantity > 0){
lvSend["item_name_"+j] = aItem[i].instance.id;
lvSend["amount_"+j] = aItem[i].price;
lvSend["quantity_"+j] = aItem[i].quantity;
j++;
}

}
lvSend.send("https://www.paypal.com/cgi-bin/webscr", "_self", "POST");
}
rendered @ Wed Apr 23 14:58:36 CEST 2014