Friday, May 28, 2010

Flash with PHP interaction

Flash with PHP interaction:
code in AS3.0

var userId:Number=10001;
var credit:Number=52;
var ticket:Number=10;
var varsToSend:URLVariables
function submitData(e:MouseEvent):void {
    varsToSend = new URLVariables();
    varsToSend.userId=userId;
    varsToSend.creadit=credit;
    varsToSend.ticket=ticket;

    // Create URL Request, set to POST, and attach data
    var formRequest:URLRequest=new URLRequest("score.php");
    formRequest.method=URLRequestMethod.POST;
    formRequest.data=varsToSend;

    // Create URL Loader, attach listeners, and load URL Request
    var varLoader:URLLoader=new URLLoader  ;
    varLoader.addEventListener(Event.COMPLETE, onLoaded);
    varLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    varLoader.load(formRequest);
}

function onLoaded(e:Event):void {
    reciveData();
// success actions
}

function ioErrorHandler(e:IOErrorEvent):void {
    // I/O error actions
}
//
function reciveData():void {
    useridTxt.text=varsToSend.userId;
    creditTxt.text=varsToSend.credit;
    ticketTxt.text=varsToSend.ticket;
}
sendDataBtn.addEventListener(MouseEvent.CLICK, submitData);

code in PHP:

if(isset($_REQUEST['userId']))
{
    $userId = $_REQUEST['userId'];
    $creadit = $_REQUEST['creadit'];
    $ticket = $_REQUEST['ticket'];
}
 

No comments:

Post a Comment