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

  • 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 118
Sample Applications 41
To write the server-side ActionScript for this sample:
1 Create a new file using your server-side ActionScript editor, and write an event handler for
when the user connects. In it, you’ll receive the name passed in by the client, accept the client
connection, create a message that uses the clients name, and call the client
msgFromSrvr
function to return the message.
application.onConnect = function(newClient, name) {
// Give this new client the same name as the user name
newClient.name=name;
// Accept the new client’s connection
application.acceptConnection(newClient);
// Create a customized "Hello [client]" message
// that the server will send to the client
var msg = "Hello! You are connected as: " + newClient.name;
// Print out status message in the application console
trace("Sending this message: " + msg);
// Call the client function, message, and pass it the msg
newClient.call("msgFromSrvr", false, msg);
}
2
Save the file as main.asc in a doc_hello directory under the flashcom applications directory.
Note: Save this main.asc file where you’ve chosen to store your server-side application files. For example, if you
chose Developer Install during installation, save this file to the same directory where you’ve stored the client-side
SWF file and its source FLA file. If you chose Production Install and you have a Web server, the Flash
Communication Server will look for your client-side files under \flashcom\applications in your Web server's root
directory and will look for your server-side application files (including this main.asc file) under \applications in the
directory you specified during installation. The <AppsDir> tag in the Vhost.xml server configuration file contains
the location of your flashcom application directory. For more information see Chapter 1, “The flashcom
application directory,” on page 15.
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 the SWF file in the application directory.
3 Overwrite the text in the login box by typing your name, then click Connect. You’ll see a
message like this one:
Hello! You are connected as: [your name]
Sample 5: Text Chat
In the Shared Text example (see “Sample 2: Shared Text” on page 35), you created a remote
shared object that enabled a user to view another user’s typing in real time, letter by letter. In this
next sample, you’ll create a different kind of shared object that sends whole messages on
command. You’ll also add several elements to make the text chat application more versatile,
including fields for logging in, typing in a chat room name, and viewing the list of current
participants.
Vue de la page 118
1 2 ... 114 115 116 117 118 119 120 121 122 123 124 ... 368 369

Commentaires sur ces manuels

Pas de commentaire