PHP send var to AS3 with AJAX or POST

流过昼夜 提交于 2020-01-03 03:51:47

问题


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
}

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


回答1:


You'd have to do it on the php side

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

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



来源:https://stackoverflow.com/questions/14634808/php-send-var-to-as3-with-ajax-or-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!