PHP发送VAR到AS3与AJAX或POST

问题描述:

所有的教程中,我发现使用某些文件的XML,TXT,或与之呼应的PHP。让增值经销商,以AS3有没有办法做到这一点没有回声或文件。说我查询PHP page.php从Flash AS3用某种方式和page.php过程响应

All tutorial i found use some file xml, txt, or php with echo. to give vars to AS3 is there way to do it without echo or file. Say i query PHP page.php from flash with AS3 somehow and process response from page.php

var loader:URLLoader = new URLLoader();   
var request:URLRequest = new  URLRequest("http://mysite.com/test.php");           
loader.load(request);

loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

function loaderIOErrorHandler(event:IOErrorEvent):void{
    trace("ioErrorHandler: " + event);
}

function completeHandler (event:Event):void {

    this.text1.appendText(loader.data.mykey); //Whatever dataField1 you saved as
}

这是工作,但我如何使它查询PHP和处理其反应如何?

That works, but how do i make it query php and process its response?

您不得不这样做在PHP端

You'd have to do it on the php side

var request:URLRequest = new  URLRequest("http://mysite.com/test.php?pid=984")

等。基本上,所有你能做的就是用Flash一个AJAX式的GET请求,然后将数据返回到Flash。

Etc. Basically, all you can do is an AJAX-like get request with flash, then return the data to flash.