AS2:
1. client_nc.showmsg = function (msg) {
2. Txtchat.text + msg;
3.};
Copy Code
AS3:
1. Private function receives object (content): void {
2.//trace ("Onreply received value:" + result);
3. textlbl.text+= content;
4.}
Copy Code
But then, the server says it can't find the receiver, what's going on? The following is the completion of the code, master advice.
Client:
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 ();
private Var myresponder:responder=new responder (receiving object);
Public Function HelloWorld () {
textlbl.text= "123";
Connectbtn.label= "Connect";
Connectbtn.addeventlistener (Mouseevent.click,connecthandler);
Nc.addeventlistener (Netstatusevent.net_status,onstatus_fun);
Btn.addeventlistener (Mouseevent.mouse_down, send content);
17.}
Public Function send content (me:mouseevent): void {
Nc.call ("Serverhellomsg", Myresponder, "World", Txt.text);
//TEXTLBL.VERTICALSCROLLPOSITION=TEXTLBL.TEXTFIELD.MAXSCROLLV
21.}
Public Function Onstatus_fun (e:netstatusevent): void {
var info=e.info;
Trace (Info.code);
Switch (info.code) {
Case "NetConnection.Connect.Success":
Trace ("Successful connection" +info.level);
break;
Case "NetConnection.Connect.Closed":
Trace ("has left" +info.level);
break;
Case "NetConnection.Connect.Failed":
Trace ("Connection failed" +info.level);
break;
35.}
Trace ("info.code=" +info.code);
Panax Notoginseng Trace ("info.level=" +info.level);
38.}
Public Function Connecthandler (event:mouseevent): void {
if (Connectbtn.label = = "Connect") {
Trace ("Connecting ...");
Nc.connect ("RTMP://TANKAI1260.GICP.NET/8");
Nc.call ("Serverhellomsg", Myresponder, "World", 123);
Connectbtn.label= "Disconnect";
.} else {
("Disconnecting ...");
Nc.close ();
Connectbtn.label= "Connect";
Textlbl.text= "";
50.}
51.}
The private function receives the object (content): void {
//trace ("Onreply received value:" + result);
textlbl.text+= content;
55.}
56.}
57.}
Copy Code
Server side:
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 ("Receive object", mm)
8.}
9. Application.acceptconnection (client);
10.}
Workaround:
Nc.client = this;