MACROMEDIA FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY Specifiche Pagina 114

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 369
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 113
Chapter 3 36
2 Open a connection to the server.
// Open connection to server
client_nc = new NetConnection();
client_nc.connect("rtmp:/doc_text/room_01");
3
Handle the messages coming from the server.
// Handle status message
client_nc.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code);
}
4
Initialize the typing stage.
TypingStage.text = "";
5
Get a remote shared object to hold the text data from the client.
// Create a remote shared object. client_nc.uri is the URI of the
// NetConnection the shared object will use to connect to the
// server.
text_so = SharedObject.getRemote("sharedtext", client_nc.uri, false);
6
When you get a shared object, make sure you connect to it.
// The following is very important, nothing happens otherwise
text_so.connect(client_nc);
7
Create an onSync callback function to handle the text message.
// Each time something changes in the shared object, the server
// sends out a synchronization message. This onSync handler
// updates the movie based on the information.
text_so.onSync = function(list) {
// Update the text area in the typing stage with the latest
// text from the shared object. The ’for’ loop condition searches
// through the list of changes, and the ’if’ condition ensures
// that we apply the relevant change only if someone other than
// this client has changed the value.
for (var i = 0; i < list.length; i++)
if (list[i].name == "textValue" && list[i].code != "success")
{
TypingStage.text = text_so.data.textValue;
break;
}
};
8
When the text in the typing stage changes, update the shared object with the new text.
// Update the shared object every time the user types in new text
TypingStage.onChanged = function()
{
text_so.data.textValue = TypingStage.text;
};
To test your sample application:
1 In the Flash MX authoring environment, after you have saved your work, publish it by
selecting File > Publish.
2 Open two instances of the SWF file in the application directory.
3 Type in one text box to see the other immediately updated.
Vedere la pagina 113
1 2 ... 109 110 111 112 113 114 115 116 117 118 119 ... 368 369

Commenti su questo manuale

Nessun commento