Pages

May 3, 2011

Adobe Flash CS3,CS4,CS5 (ActionScript 3.0 AS3) - Send Data (SendData) to a URL or PHP or ASP Page as Post or Get Method Example

Adobe Flash CS3,CS4,CS5 (ActionScript 3.0 AS3) - Send Data (SendData) to a URL or PHP or ASP Page as Post or Get Method Example
by using this method we can send email to our clients.


Tested on Flash ActionScript 3.0(AS3) - 

function send_data_to_url():void
{
var url_var:URLVariables = new URLVariables();
url_var.email = "auk.junk@live.com";

 url_var.first_name      = "Alim";
 url_var.middle_name   = "Ul";
 url_var.last_name           = "Karim"; //Alim Blog
 url_var.blog             = "Blog";
 //add as much as you want.
 trace(url_var);

sendData("example.php",url_var); //or use asp page url

}

function sendData(url:String, _vars:URLVariables):void
{
var request:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
request.data = _vars;
request.method = URLRequestMethod.POST; //Set Get Method if you want
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(request);

}
function handleComplete(event:Event):void
{
var loader:URLLoader = URLLoader(event.target); // send request complete , you can do   what ever you want
}
function onIOError(event:IOErrorEvent):void
{
//a.text = "Error loading URL."; // print error in a textfield
}


Tags:

Flash ActionScript,

SendData,

to url,

ASP ,

PHP,AS3

1 comment: