MACROMEDIA FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY Spécifications Page 123

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 369
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 122
Sample Applications 45
13 Create the setHistory function that the server calls to update the text in the History
dynamic text box.
// Update the History on the server with the message
client_nc.setHistory = function(msg) {
_root.History.text = msg;
}
To write the server-side ActionScript for this sample:
1 Create a new file using your server-side ActionScript editor, and write the event handler
onAppStart for initializing the application variables.
application.onAppStart = function()
{
trace("Begin sharing text");
// Get the server shared object users_so
application.users_so = SharedObject.get("users_so", false);
// Initialize the history of the text share
application.history = "";
// Initialize the unique user ID
application.nextId = 0;
}
2
Write the event handler onConnect for managing users and sending the history to all clients.
application.onConnect = function(newClient, name)
{
// Make this new client’s name the user’s name
newClient.name = name;
// Create a unique ID for this user while incrementing the
// application.nextID.
newClient.id = "u" + application.nextId++;
// Update the users_so shared object with the user’s name
application.users_so.setProperty(newClient.name, name);
// Accept the client’s connection
application.acceptConnection(newClient);
// Call the client function setHistory, and pass
// the initial history
newClient.call("setHistory", null, application.history);
// The client will call this function to get the server
// to accept the message, add the user’s name to it, and
// send it back out to all connected clients.
newClient.msgFromClient = function(msg) {
msg = this.name + ": " + msg + "\n";
application.history += msg;
application.users_so.send("msgFromSrvr", msg);
}
}
Vue de la page 122
1 2 ... 118 119 120 121 122 123 124 125 126 127 128 ... 368 369

Commentaires sur ces manuels

Pas de commentaire