首页 > 设计 > WEB开发 > 正文

21.4.调用Flash Remoting方法

2023-08-14 18:53:56
字体:
来源:转载
供稿:网友
问题
我想调用Flash Remoting 方法
解决办法
使用NetConnection 对象连接Flash Remoting网关并用call( ) 方法调用方法
讨论
Flex和Flash都有ActionScript APIs 来调用Flash Remoting 方法,不过这一节将讨论用最底层的解决办法。

所有Flash Remoting 方法都基于flash.net.NetConnection 类,首先要创建NetConnection 对象:
+展开
-ActionScript
var connection:NetConnection = new NetConnection( );

下一步调用connect( )方法,传递进Flash Remoting网关的URL,例如:
+展开
-ActionScript
connection.connect("http://localhost:8500/flashservices/gateway/");

下面的代码连接AMFPHP Flash Remoting 网关:
+展开
-ActionScript
connection.connect("http://www.rightactionscript.com/flashremoting/gateway.php");

connect( ) 方法并不会立即连接网关URL,如果URL不合法或服务器发生异常,都不会收到错误直到真正调用方法之后。

下一步就是用NetConnection对象的call( )方法调用Flash Remoting方法,call( )方法需要两个参数,第一个参数指定方法名称和路径,第二个参数指定响应处理函数,如果不需要处理函数,可直接设为null。

第一个参数用点分隔符格式的路径:
package.ServiceObject.method
如果用ColdFusion 组件(CFC),可访问http://localhost:8500/com/oreilly/as3cb/Example.cfc, 定义的
方法叫test( ) :
+展开
-ActionScript
connection.call("com.oreilly.as3cb.Example.test"null);

可以继续在后面添加参数,例如test( ) 方法接收一个数字和字符串作为参数,可这样写:
+展开
-ActionScript
connection.call("com.oreilly.as3cb.Example.test"null, 15, "abcd");
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表