问题
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