
Chapter 3 42
About the sample
In a chat room, you want to view current users dynamically. When users log in to a room, the list
should be updated; when users log off, they should be removed from the list. It’s best to do this
processing work on the server, because keeping data centrally on the server means that any client
can come and go, and the data will always be accurate and available.
In addition, in this example, the server doesn’t simply hand off the text from one client to
another, it actually makes changes to the message by adding the name of the user who typed it.
Because you expect the server to provide this functionality, you need to write some server-side
ActionScript to handle this work.
Finally, this example also illustrates how to dynamically add an instance name to a
NetConnection.connect command based on data entered by the user.
Re-creating the sample
The doc_textchat.fla file provides the ActionScript for letting multiple users share text in
real time.
See “Creating your working environment” on page 31 before you start to re-create the sample.
To create the user interface for this sample:
1 In the Flash MX authoring environment, select File > New to open a new file.
2 From the toolbox, select the Text tool and draw two text boxes. In the Property inspector
(Window > Properties), select Input Text for the type of text box, and give one the instance
name
User, and the other, Room.
3 From the toolbox, select the Text tool and draw another text box. In the Property inspector,
select Input Text for the type of text box, and give it the instance name
Message.
4 From the toolbox, select the Text tool and draw a fourth text box. In the Property inspector,
select Dynamic Text for the type of text box, and give it the instance name
History.
5 To add a place where users are listed, open the Components panel (Windows > Components),
drag the List Box component onto the Stage, and give it the instance name
People.
6 To add the button for connecting to the server, drag a push button from the Components
panel onto the Stage. In the Property inspector, give it the instance name
Connect_btn, the
label
Connect, and the click handler doConnect.
7 To add the button for sending messages, drag a push button from the Components panel onto
the Stage. In the Property inspector, give it the instance name
Send_btn, the label Send, and
the click handler
doSend.
8 Create a directory named doc_textchat in your flashcom application directory, and save the file
as doc_textchat.fla in this directory.
To write the client-side ActionScript for this sample:
1 Select the keyframe in the Timeline and open the Actions panel (Window > Actions).
2 In the Actions panel, stop the progress of the movie.
stop();
Commentaires sur ces manuels