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;
我的博物馆故事 官方安卓版v1.61.2
我的博物馆故事是一款以消除为主题的经营养成类手游,在这里玩家
专业模拟飞行10 手机版v12.2.4
专业模拟飞行10安卓版是一款飞行休闲手游,顶尖的物理飞行引擎
动物起义战斗模拟器二琳同款 最新版v4.1.1
动物起义战斗模拟器是一个非常有趣的模拟类游戏,玩家可以召唤各
迷你世界七周年 安卓手机版v1.43.0
迷你世界7周年是一款由《迷你世界》官方推出的庆祝特别版本,在
劫后公司无限资源版 v1.0.5.1
劫后公司内置菜单版是游戏的破解版本,在该版本中为玩家提供了内