As3利用AMFPHP与PHP进行通讯
来自:http://bbs.9ria.com/thread-65836-1-1.html
?
首先,说下具体配置,PHP版本:5.2.5,apache:2.2.11,(或者WAMP2.2),amfpackage { import flash.display.Sprite; import flash.events.NetStatusEvent; import flash.net.NetConnection; import flash.net.ObjectEncoding; import flash.net.Responder; /** * ... * @author 纳兰容若 */ public class AMFTest extends Sprite{ private var netCon:NetConnection = new NetConnection(); private var rsp:Responder = new Responder(onSuccess, onError); private var phpUrl:String = "http://localhost/amfphp/gateway.php"; public function AMFTest() { netCon.objectEncoding = ObjectEncoding.AMF3; netCon.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); netCon.connect(phpUrl); netCon.call('HelloWorld.getData', rsp); } private function onNetStatus(e:NetStatusEvent):void { trace("failed"); } private function onSuccess(rspObj:Object):void { trace("ok: "+rspObj); } private function onError($rspObj:Object):void { trace("AMF client error."); } }}
?
<?phpclass HelloWorld { /** * @desc 向用户表示友好问候 * @access remote * @returns String */ public function getData() { return "Hello World"; }}?>php文件命名为 HelloWorld.php,放到 D:\webroot\amfphp\services中。(注意:D:\webroot是我的web根目录,这个具体设置要看你自己的。)
如果链接出现问题,则有可能是如下错误导致的:
?
Fatal error: Uncaught exception 'VerboseException' with message 'Standalone Flash player disabled. Update gateway.php to allow these connections' in C:\wamp\www\amfphp\core\amf\app\Gateway.php on line 357 VerboseException: Standalone Flash player disabled. Update gateway.php to allow these connections in C:\wamp\www\amfphp\core\amf\app\Gateway.php on line 357 Call Stack: 0.0003 374432 1. {main}() C:\wamp\www\amfphp\gateway.php:0 0.0062 874840 2. Gateway->disableStandalonePlayer() C:\wamp\www\amfphp\gateway.php:137 0.0062 875056 3. trigger_error() C:\wamp\www\amfphp\core\amf\app\Gateway.php:357 0.0062 875720 4. amfErrorHandler() C:\wamp\www\amfphp\core\amf\app\Gateway.php:357
?
此时只需要按提示,打开gateway.php文件,屏蔽掉原135、137行即可。
?