#include "NKConnector.as" // Handlers object _root.myHandlers = new Object(); _root.myHandlers.readData_Handler = function (result) { // set the recieved data , ie string, to the variable that holds the chat text _root.chatData = result; // modify the scoll so we display the last line of the chat _root.chatData.scroll = _root.chatData.maxscroll; }; _root.myHandlers.appendData_Handler = function (result) { // if result is true we read data from the chat to update the chat window // else send an error message to this chat window only if(result) _root.myChat.readData("nkChatDemo"); else _root.chatData += "\n--- Error writing data to server ---\n"; }; // send button action _root.sendMessage = function() { // write the mesage to the remote object _root.myChat.appendData("nkChatDemo", _root.userName + " : " + _root.message + "\n", false); // clear the message text box _root.message = ""; } // myChat // create a new NKConnector for the nkRemoteObject _root.myChat = new NKConnector("http://nuthing.com/flashconnect/trapper/trapper.php", "nkRemoteObject", _root.myHandlers, true); // set the two methods we will use _root.myChat.setMethod("appendData"); _root.myChat.setMethod("readData"); // setIndicator _root.setIndicator = function () { if(_root.myChat.isBusy("readData")) { _root.indicator_mc.status = "Getting data from server ..."; _root.indicator_mc.gotoAndStop(1); } else if(_root.myChat.isBusy("appendData")) { _root.indicator_mc.status = "Sending data to server ..."; _root.indicator_mc.gotoAndStop(1); } else { _root.indicator_mc.status = "Ready."; _root.indicator_mc.gotoAndStop(2); } } // set interval, to have the funciton be called every so often setInterval(_root.setIndicator,100); // set a default user name _root.userName = "Guest" + random(200); stop();