how to post data from actionscript 3.0 to php or asp.net sample

this a small example for sending and retrieving data from serverside scripts like php , asp.net or any thing


package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;

/**
* ...
* @author Anil Mathew
*/
public class Main extends Sprite
{
public var loader:URLLoader; //url loader
private var _url:String // the url string
private var _req:URLRequest; // url request
public var _vars:URLVariables; // url variables
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
_url = "http://www.yahoo.com/";// url where we need to post the data
_req = new URLRequest(_url);// url request instance
_req.method = URLRequestMethod.POST ; // metheod to use for the request
_vars = new URLVariables();// url variables
_vars.name = "Myname"; // sending name
_vars.age = 21; //sending age
loader = new URLLoader(); //loader instance
loader.load(_req); //loading request
loader.addEventListener(Event.COMPLETE, completeHandler);// event handler for complete event


}

private function completeHandler(event:Event):void {
trace(event.target.data); // returned data
}


}

}

0 comments:


PHP developer Cochin |PHP developer Kerala | PHP developer India | Flash developer/programmer Cochin | Flash developer/programmer Kerala | Flash developer/programmer India | web programmer kerala |web programmer Cochin |web programmer India |web developer kerala |Web developer Cochin | Kerala PHP | PHP freelancer| flash actionscript freelancer