Prerequisite knowledge

Knowledge of ActionScript 3 and Flex is required to make the most of this article.


Additional required product:

Adobe Connect Collaboration Builder SDK

User level


In a previous article, I described a simple multiuser snake and ladder game that I built using the Adobe Connect Collaboration Builder SDK. That article showed you how to synchronize SWF files that are loaded into Share pods in Adobe Connect meeting rooms using a Flex component included in the Adobe Connect Collaboration Builder SDK. This capability makes it easy to build multiuser games in which the SWF applications communicate with one another. In this article, I describe Sudoku Contest, which, unlike the snakes and ladders example, supports more than two players.

Sudoku Contest is a multiplayer game in which each contestant receives the same Sudoku puzzle that is generated by the host. The host has the ability to stop the contest (after a sufficient amount of time has elapsed), broadcast the solution, and end the contest.

Game overview

After uploading the SudokuContest.swf into a Share pod, the host generates a Sudoku puzzle by clicking Generate Sudoku (see Figure 1).

The Sudoku puzzle is then presented to all meeting attendees, including the host. Once a user solves and submits the puzzle, the user's name, result, and elapsed time is added to a data grid, which is visible to all attendees. After an attendee has submitted a solution, his Sudoku puzzle panel will be disabled. The host can stop the contest at any time by clicking the Time Up button, which disables each contestant's Sudoku puzzle panel. The host can also broadcast the solution to all contestants.

How the game works

The Sudoku Contest game was written completely in ActionScript 3, making use of the Collaboration Builder SDK to synchronize events.

As with the snakes and ladders game, I loaded SyncConnector.swc—a Flex component that enables synchronization of multiple SWF files—as a library in Flash Builder and added it to the application.

To access the Collaboration Builder SDK API from an application, you need a SyncConnector instance; for example:

<components:SyncConnector id="sudokuConnector"/>

The application uses sudokuConnector, an instance of SyncConnector, to communicate with other application instances.

On creationComplete, the Sudoku Contest application adds event listeners for the CAUGHT_UP and SYNC_MSG_RCVD events:

syncConnector.addEventListener(SyncSwfEvent.CAUGHT_UP,<caughtUpHandler>); syncConnector.addEventListener(SyncSwfEvent.SYNC_MSG_RCVD,<syncMsgRcvd>);

You may recall that every application that uses the SyncConnector component goes through a catch-up phase when it is loaded into a Share pod. This phase allows new attendees to receive the accumulated state of the application. After all messages are received, SyncConnector dispatches a CAUGHT_UP event.

The CAUGHT_UP event handler can perform any operations that are required immediately after the SWF loads (as long as they do not need to dispatch any sync messages). In this application, for example, the handler ensures that any new participant entering the room is shown the current puzzle if a contest has already started.

The SYNC_MSG_RCVD event handler is invoked when events are received. For example, in Sudoku Contest, this event handler is invoked when a new puzzle is generated and sent to the attendees. When the host clicks the button to generate a Sudoku puzzle, the application creates a random puzzle in the form of a 9 × 9 matrix (see Figure 2). This matrix is dispatched to all the attendees using the dispatchSyncMessage API of the Collaboration Builder SDK:

sudokuConn.dispatchSyncMessage("sudokuGenerated", Sudoku, false);

It is received by all the contestants in the SYNC_MSG_RCVD handler, syncMsgRcvd(evt:SyncSwfEvent). For example:

if ("sudokuGenerated"){ Sudoku=evtData.msgVal as Array; currentState="contest"; ..}

Each client uses the matrix received in syncMsgRcvd to create and display the puzzle.

When a contestant completes the puzzle and submits a solution, it is evaluated on the client side and the user's information is added to the DataGrid component, which is also synchronized across all attendees. When the host selects Broadcast Solution, the correct answer will be revealed to all attendees (see Figure 3).

The application uses states to manage the different views. The main screen, for example, is different for the host and participants. The code checks sudokuConn.role and sets the value of currentstate appropriately:

if(sudokuConn.role=="owner") currentState="host"; else currentState="participant";

The data grid displays information on any contestant who has submitted a puzzle solution. Each participant must have permission to publish his or her information before calling dispatchSyncMessage:

dispatchSyncMessage: sudokuConn.allowParticipantPublish("gridObject", true); sudokuConn.dispatchSyncMessage("gridObject", obj, false);

The Flex DataGrid component can be easily sorted by elapsed time to identify the winner. When the host clicks End Contest, the game is over (see Figure 4).

Where to go from here

The current version of Sudoku Contest has just one level of difficulty and supports only 9 × 9 puzzles. One possible enhancement is to allow the host to select easy, medium, and hard puzzles as well as use a bigger matrix.

If you have not already done so, you may want to read my companion article, Building a multiuser snake and ladder game using the Adobe Connect Collaboration Builder SDK.

See Using the Adobe Connect Collaboration Builder SDK 2.0 (PDF, 200 KB) for additional details, including instructions on how to test an application in Flash Builder without Adobe Connect 8.

To download the Adobe Connect Collaboration Builder SDK, visit the Adobe Connect Developer Center.

If you are interested in seeing the current state of the sample files I used when writing this article, send me an e-mail at