486 | Chapter 13: Symmetric Proxy Pattern
player’s move. The client-side script checks which player is making the move and
assigns the move to the proxy player. The rest of the connection function deals with
housekeeping.
The third part (application.onDisconnect) takes care of further housekeeping by
resetting the Boolean variables. It also lets the player know the number of players
currently connected. When working with applications over the Internet, letting
remotely connected players know whether anyone’s connected is an essential
ingredient.
Player-Proxy Classes
The main implementation of theISymPlayeris in two classes, each representing one
of two players. The classes are virtually identical except for identifying themselves as
either “player1” or “player2” to the media server. Also, each contains a proxy for its
opponent, giving it the androgynous character described previously in this chapter.
Example 13-5 shows the script for the entire class. It can be broken down into six
parts:
- Imports the necessary name spaces and classes.
- Establishes variables required for the different methods.
- Contains the Constructor function. This includes all the necessary connection
statements, calls to the text field and button functions, and event listeners for the
four buttons. - Implements the si xmethods from the interface in the order in which they appear
in the interface. This is the core of the class. - Checks to see if connection has been made and if so, turns on the connection light
and sets up the client-side shared object. Also, this function establishes the shared
object and connects the shared object through theNetConnectioninstance (nc).
Finally, it calls the server-side script function checkPlayNum( ). This call is a
“bounce” in that it triggers the server-side function that sends the number of con-
nected users right back to the client-side functionnumConnect( ). - Sets up the text fields and buttons.
By placing Example 13-4 and Example 13-5 side by side, you can better see the interac-
tion between the client-side class and the server-side application. (The.ascfiles are not
actually classes, but they have much in common with a class.) Wherever you seenc.
call("functionName",p1,p2)in theSymPlayer1class, it’s a reference to a function in
the server-side script. Likewise, in the server-side script, anyapplication.ss_so.
send(“functionName”,p1)is a reference to a function in theSymPlayer1orSymPlayer2
classes.