ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Information Shared Over the Internet | 485

The program is broken down into three main parts. The first part launches only


when the application first starts (application.onAppStart). Either player can initially


launch the server-side script, and, once launched, it won’t launch again until both


players have quit the application, and it’s not launched again until about 20 minutes


after the last player has quit.


You may be wondering if the comment about ActionScript being ver-
sion 1.0 when everything else in this book is written in ActionScript 3.0
is a typographical error. No, there’s no typo. The subset of Action-
Script build for FMS2 changed little from the original Server Side Com-
munication ActionScript (SSCA) released with Flash Communication
Server (FCS). When FMS2 was released, ActionScript 2.0 was part of
the Flash package, but couldn’t be used for server-side coding. So,
while SSCA is slightly different from standard ActionScript in any for-
mat, it’s also a different version.

The second part of the script launches during the time the application is being used


by either player beginning with the attempt to connect to the application


(application.onConnect). It generates a default value (“ready”) for the moveNow


variable, and checks to see if the correct names are used, and the number of players


connected. The function to assign a move to the shared object (currentClient.


makeMove) serves to record both the move and which player made the move. A string


separated by a tilde (~) character is then sent to all players (application.ss_so.


send). The tilde is used to identify the line of demarcation between the player and the


{

var c2=application.clients.length;
application.ss_so.send("numConnect",c2);
}
};


//------------------------
application.onDisconnect = function(currentClient)
{
dupeName=currentClient.name;
if(dupeName=="player1")
{
this.dup1=false;
}
else
{
this.dup2=false;
}
trace("disconnect: "+currentClient.name);
this.ss_so.setProperty(currentClient.name,null);
c2=application.clients.length;
application.ss_so.send("numConnect",c2);
};


Example 13-4. proxygame.asc (continued)

Free download pdf