尝试连接到 AMFPHP - NetConnection.connect() 返回 TypeError: Error #1009
更新:现在我已将 AMFConnection var 声明移至 Main 中的函数外部,并注释掉了一些 trace() 命令,现在它给出了新的错误:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at AMFConnection/init()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:32]
at AMFConnection()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:23]
at Main/testConnection()[/Users/Jan/Downloads/amfphp1/Main.as:14]
at Main()[/Users/Jan/Downloads/amfphp1/Main.as:10]
所有这些本质上都指向 AMFConnection 的 NetConnection 初始化: _netConnection = new NetConnection();
(其中 _netConnection 在类的开头声明)
我正在尝试连接到服务器上的 AMFPHP(使用 Flash AS3),并且 swf 在到达 .connect() 阶段时停止运行。为了使事情变得更容易(?)和更可重用(?),我将所有 NetConnection 机制放入一个单独的类 AMFConnection 中,我从主文档类中调用它,如下所示(详细信息已更改):
public function testConnection(e:*=null):void {
var conn:AMFConnection = new AMFConnection();
conn.table = "some_table";
conn.selections = "*";
conn.conditionals = "WHERE something = 'something'";
conn.service = "QueryAMF";
conn.method = "makeQuery";
conn.displayText = txt;
conn.gogogo("http://www.someplace.com/Amfphp");
}
AMFConnection 实际上启动连接并使用函数 gogogo() 调用 AMFPHP 服务,而 connect() NetConnection 函数在这里不起作用。这是 AMFConncection 类的主要部分
private var _netConnection:NetConnection;
private var _responder:Responder;
function AMFConnection()
{
init();
}
private function init(e:* = null)
{
_netConnection = new NetConnection();
_responder = new Responder(uponResult);
}
public function gogogo(url:String):void {
trace(url);
_netConnection.connect(url);
_netConnection.call(String(service+"/"+method), new Responder(onResult, null), table, selections, conditionals);
}
快速调试会话显示以下错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AMFConnection/gogogo()[AMFConnection.as:44]
at Main/testConnection()[Main.as:20]
at Main()[Main.as:8]
其中:Main.as:20 = conn.gogogo(...)
和 AMFConnection.as:44 = _netConnection.connect(url)
;
它也无法显示舞台,而是显示加载点。现在,最终我要将此应用程序移至与 AMFPHP 服务相同的服务器,但即使我使用相对 url(而不是绝对 url)尝试它,它仍然会在 connect() 处崩溃。我尝试将发布设置从仅本地更改为仅网络,但无济于事。
有什么线索吗?知道本地连接 AMFPHP 的更好方法吗?
提前干杯! JB
附注帖子已更新,请参阅页面顶部。
UPDATE: Now I've moved the AMFConnection var declaration to outside the functions in Main, and commented out some trace() commands, and now it gives new errors:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at AMFConnection/init()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:32]
at AMFConnection()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:23]
at Main/testConnection()[/Users/Jan/Downloads/amfphp1/Main.as:14]
at Main()[/Users/Jan/Downloads/amfphp1/Main.as:10]
All of these essentially point to AMFConnection's NetConnection initialisation: _netConnection = new NetConnection();
(where _netConnection is declared at the beginning of the class)
I'm trying to connect to AMFPHP on a server (with Flash AS3), and the swf borks when it reaches the .connect() stage. To make things easier (?) and more reusable (?), I've put all the NetConnection mechanics into a separate class, AMFConnection, which I call from the Main document class like this (details changed):
public function testConnection(e:*=null):void {
var conn:AMFConnection = new AMFConnection();
conn.table = "some_table";
conn.selections = "*";
conn.conditionals = "WHERE something = 'something'";
conn.service = "QueryAMF";
conn.method = "makeQuery";
conn.displayText = txt;
conn.gogogo("http://www.someplace.com/Amfphp");
}
AMFConnection actually starts the connection and calls the AMFPHP service with the function gogogo(), and here's where the connect() NetConnection function just won't work. Here's the main section of the AMFConncection class
private var _netConnection:NetConnection;
private var _responder:Responder;
function AMFConnection()
{
init();
}
private function init(e:* = null)
{
_netConnection = new NetConnection();
_responder = new Responder(uponResult);
}
public function gogogo(url:String):void {
trace(url);
_netConnection.connect(url);
_netConnection.call(String(service+"/"+method), new Responder(onResult, null), table, selections, conditionals);
}
A quick debug session reveals the below errors:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AMFConnection/gogogo()[AMFConnection.as:44]
at Main/testConnection()[Main.as:20]
at Main()[Main.as:8]
Where: Main.as:20 = conn.gogogo(...)
, and AMFConnection.as:44 = _netConnection.connect(url)
;
It also fails to display the stage, instead showing the loading dots. Now, eventually I'm going to move this application to the same server as the AMFPHP service, but even when I try it there with a relative url, instead of an absolute one, it still breaks down at connect(). I've tried changing the publish settings from local only to network only, to no avail.
Any clues? Know a better way to connect to AMFPHP locally?
Cheers in advance!
JB
P.S. Post updated, see top of page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,我更喜欢使用包含 sql 和 params 的 php 文件。但是嘿...
我猜您可能会收到此错误的最明显原因是网址中的错误。我相信标准 gateway.php 是在没有大写 G. 的情况下编写的,并且不位于 core 文件夹中,而是位于 amfphp 文件夹中。但话又说回来,我不知道你改变了什么。
first, i prefer to use a php file which contains my sql and params. but hey...
The most obvious reason why you might get this error would be a fault in the url i guess. I believe that the standaard gateway.php is written without a capital G. and does not situate itself in the core folder but in the amfphp folder. but then again I don't know what you have altered.
您的 _netConnection 必须为 null,并且您对 null 引用调用 connect() 方法,因此您会以 NullPointerException 结束。向我们展示如何初始化 _netConnection :)。
Your _netConnection must be null, and you call connect() method on null reference, so you finish with NullPointerException. Show us how you initialize _netConnnection :).
好吧,我基本上重新制作了这个东西,几个小时后,它决定工作。我不知道怎么做,但是……呃。
感谢大家的帮助
Ok, I basically remade the thing, and after a couple of hours, it decided to work. I'm not sure how, but... eh.
Thanks all for your help