Flash Remoting经验不足

晚上根据AMFPHP Installation Guide上 摆弄AMFPHP(不过这几天该Project在sourceforge上讨论改名的事,所以有条新闻"AMFPHP is dead, INFRNO long life"吓了我一跳,以为那么好个东西突然夭折...),到了写Actionscript代码的时候原代码是如此:

#include "NetServices.as"
#include "NetDebug.as"

// ----------------------------
// create the responder object
// In this object we will define
// all the result function for
// the data received from server
// ----------------------------
mainResponder = new Object();
// echoString receiver
mainResponder.echoString_Result = function( data ){
    trace("echoString result")
    trace("received: " + data )
    trace("----")
}
// echoDate receiver
mainResponder.echoDate_Result = function( data ){
    trace("echoDate result");
    trace("received: " + data)
    trace( data instanceof Date )
}
// generic onStauts responder, it will be invoked
// when an error is received from the server
mainResponder.onStatus = function ( data ) {
    trace("an error occurred")
    trace("in line: " + data.line)
    trace("error level: " + data.level)
    trace("description: " + data.description)
}
// define the path of our gateway.php
NetServices.setDefaultGatewayUrl('http://localhost/flashservices/gateway.php');
// initialize a variable for the connection
conn = NetServices.createGatewayConnection();
// initialize the service for our class EchoTest
// an tell which is the responder object
// for all the calls to the server
serv = conn.getService("EchoTest", mainResponder);

// now, call the server method 'echoString'
serv.echoString("this is a test");

// if you want to call also the echoDate method
// just de-comment the follow line:
// serv.echoDate(new Date());


无论如何都出现"Error opening include file NetServices.as: File not found."和NetDebug.as not found的错误.查了半天google在在这里发现原因,原来这些例子都是面向Flash MX的,而#include在MX2004中是不被推荐的用法( #include "NetServices.as has been depracated in MX 2004. Try this, import mx.remoting.NetServices;), 虽然没仔细查到错误原因(估计是和路径有关系,因为Classes在$sys$:\Documents and Settings下同样有套备份,如果将这两个文件拷贝到发布目录就会继续报错说这个目录下无法找到NetServices.as中引用的一些文件.)所 以说解决方法是应该使用"import mx.remoting.*;"这样的格式.如此编译成功.

但是问题没有完全解决,首先是把"// serv.echoDate(new Date());"一句注释去掉后没有显示日期,而是报:
"an error occurred
in line: 217
error level: User Error
description: no class named EchoTest is known to the gateway"
问题是EchoTest class完全可以被AMFPHP的gateway.php访问到.
还有一个错误是NetConnection Browser没有出现教程上应该有的显示.空白一片,难道是参数传不进其中?
有待继续考证.

posted on 2004-12-20 23:11  Liki  阅读(1756)  评论(1编辑  收藏  举报

导航