flash FMS AS2转AS3的连接出错
AS2:
1. client_nc.showmsg = function(msg) {
2. txtChat.text += msg;
3. };
复制代码
AS3:
1. private function 接收对象(内容):void {
2. //trace("onReply received value: " + result);
3. textLbl.text+=内容;
4. }
复制代码
但是这样,服务器说找不到接收对象,怎么回事?下面是完成代码,高手指教一下。
客户端:
1. package {
2. import flash.display.MovieClip;
3. import flash.net.Responder;
4. import flash.net.NetConnection;
5. import flash.events.MouseEvent;
6. import flash.events.NetStatusEvent;
7. import flash.text.*;
8. public class HelloWorld extends MovieClip {
9. private var nc:NetConnection=new NetConnection();
10. private var myResponder:Responder=new Responder(接收对象);
11. public function HelloWorld() {
12. textLbl.text="123";
13. connectBtn.label="Connect";
14. connectBtn.addEventListener(MouseEvent.CLICK,connectHandler);
15. nc.addEventListener(NetStatusEvent.NET_STATUS,onStatus_fun);
16. btn.addEventListener(MouseEvent.MOUSE_DOWN,发送内容);
17. }
18. public function 发送内容(me:MouseEvent):void {
19. nc.call("serverHelloMsg",myResponder,"World",txt.text);
20. // textLbl.verticalScrollPosition=textLbl.textField.maxScrollV
21. }
22. public function onStatus_fun(e:NetStatusEvent):void {
23. var info=e.info;
24. trace(info.code);
25. switch (info.code) {
26. case "NetConnection.Connect.Success" :
27. trace("连接成功"+info.level);
28. break;
29. case "NetConnection.Connect.Closed" :
30. trace("已经离开"+info.level);
31. break;
32. case "NetConnection.Connect.Failed" :
33. trace("连接失败"+info.level);
34. break;
35. }
36. trace("info.code="+info.code);
37. trace("info.level="+info.level);
38. }
39. public function connectHandler(event:MouseEvent):void {
40. if (connectBtn.label == "Connect") {
41. trace("Connecting...");
42. nc.connect("rtmp://tankai1260.gicp.net/8");
43. nc.call("serverHelloMsg",myResponder,"World",123);
44. connectBtn.label="Disconnect";
45. } else {
46. trace("Disconnecting...");
47. nc.close();
48. connectBtn.label="Connect";
49. textLbl.text="";
50. }
51. }
52. private function 接收对象(内容):void {
53. //trace("onReply received value: " + result);
54. textLbl.text+=内容;
55. }
56. }
57. }
复制代码
服务器端:
1. application.onConnect = function( client ) {
2. client.serverHelloMsg = function( helloStr,mm ) {
3. trace(helloStr)
4. trace(mm)
5. // return "Hello, " + helloStr +mm+ "!";
6. mesg=helloStr+mm
7. application.broadcastMsg("接收对象",mm)
8. }
9. application.acceptConnection( client );
10. }
解决方法:
nc.client = this;
补充:flash教程,As3.0