AS2 to AS3 migration of FMS2 Chat application
Flash Media Server March 3rd, 2008While I was trying to migrate a textChat application written in AS2 to AS3, I encountered the problem, that I couldn't use
Actionscript:
-
nc.msgFromSrvr = function (msg) {
-
chatPrintDebug ("msgFromSrvr "+msg);
as because the reference nc.msgFromSrvr does not work this way anymore.
I found a way on the Adobe Forums suggesting this way:
Actionscript:
-
var connection = new NetConnection();
-
connection.client = this;
-
connection.connect("rtmp://localhost/application", "userName");
-
-
var remoteUsers = new SharedObject();
-
remoteUsers = SharedObject.getRemote("users_so",connection.uri,false);
-
remoteUsers.connect(connection);
-
remoteUsers.client=this;
-
-
function msgFromSrvr (msg:String) { trace(msg); };
In the server-side I wrote the next code:
Actionscript:
-
application.onAppStart = function () { application.users_so = SharedObject.get("users_so",false); }
-
application.onConnect = function (userName) { application.users_so.send("msgFromSrvr","message_txt"); }
It worked fine.