search
HomeBackend DevelopmentPHP TutorialAs3利用AMFPHP与PHP进展通讯

As3利用AMFPHP与PHP进行通讯

来自:http://bbs.9ria.com/thread-65836-1-1.html

?

首先,说下具体配置,PHP版本:5.2.5,apache:2.2.11,(或者WAMP2.2),amfphp:1.9版本(附件已提供),windows xp系统。

注意:amfphp的不同的版本与php不同的版本会有冲突。具体检测方法是:在web根目录下解压amfphp后,访问该url: http://localhost/amfphp/browser/,如果没有报任何错误,那么恭喜你。如果有错误,请更换amfphp的版本。

经我的测验,上面那个配置是不会有问题的。

在具体的项目中,有时我们会使用As3纯项目,所以在As3中Amf通讯也经常用到,今天我们来讲讲在As3中的方法。(以前已经发过flex与amfphp通讯的相关文章,请查阅后台板块)
在As3端,主要就是NetConnection的使用,首先选择使用AMF3协议,这个是现在常用的,AMF0因为要兼容以前的版本,所以有些冗余。
然后使用connect方法连接后台url。
然后声明一个Responder对象,该对象在 NetConnection.call() 中使用以处理来自与特定操作成功或失败相关的服务器的返回值。
接着使用NetConnection,call 后台php端类中的方法,如本例的HelloWorld.getData,记着把是所声明的 Responder对象写到call方法的第2个参数里。

注意看Responder里两个函数参数,第一个,如果对服务器的调用成功并返回结果,则此函数被调用。例子中的onSuccess
第二个, 如果服务器返回一个错误,则此函数被调用。例子中的,onError。

好,来看看As3端:

package  {    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.");        }    }}

?

php端:

<?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行即可。

?

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

504 gateway timeout怎么解决504 gateway timeout怎么解决Nov 27, 2023 am 10:55 AM

504 gateway timeout的解决办法:1、检查服务器负载;2、优化查询和代码;3、增加超时限制;4、检查代理服务器;5、检查网络连接;6、使用负载均衡;7、监控和日志;8、故障排除;9、增加缓存;10、分析请求。解决该错误通常需要综合考虑多个因素,包括服务器性能、网络连接、代理服务器配置和应用程序优化等。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php怎么设置implode没有分隔符php怎么设置implode没有分隔符Apr 18, 2022 pm 05:39 PM

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools