This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
628
|
Chapter 15: Application Design Patterns and Best Practices
Wait for the shared object to report the change was successful before showing
the change.
Show the change immediately and again when the shared object synchronizes.
The PersonalCursor component implements the second option. The SharedBall class
listed in Example 8-4 uses the first option. When the mouse is dragging the ball, the
ball’s onMouseMove( ) method checks the x and y values to make sure they aren’t off
the Stage and then updates both the position of the ball clip and the shared object:
this.so.data[this.xSlot] = this._x = x;
this.so.data[this.ySlot] = this._y = y;
When the position updates are accepted by the server, the onSync( ) method is called
with a list containing an information object with
code set to “success”. The Shared-
Ball class simply ignores “success” messages. It updates its position only when some-
one else moves the ball and onSync( ) is passed a list containing an information
object with a
code value of “change” or “reject”. A “reject” code indicates the user’s
attempt to move the ball was rejected by the server in favor of another client’s posi-
tion update.
You might think that there is never a reason to update the visible state of an applica-
tion before and after the changes are synchronized in the shared object. Samuel Wan
posted a nice sample application that makes good use of the third option. The
ScratchPad component, made available as part of his Flash Forward 2003 NY sam-
ple files, updates the screen while the user draws on the scratch pad. When the draw-
ing is complete, the graphic is removed from the Stage and the graphic information is
sent to the server where it is stored in a shared object. When the shared object syn-
chronizes, the original drawing is redrawn on the Stage. From the user’s perspective,
the two-step update sequence is a good choice. The user can draw and see immedi-
ately what the drawing looks like but is also made aware of the delay between releas-
ing the mouse and everyone else seeing the drawing. The source files are available at:
http://www.samuelwan.com/information/archives/000157.html
Example 17-6 demonstrates a fourth option, which is attempting to anticipate an
object’s future position based on its current speed and direction of movement, but
we save that discussion for Chapter 17.
Interval Update Checks
The ScratchPad component waits until the user has completely drawn a shape before
sending the drawing information to the server, whereas the PersonalCursor compo-
nent updates the shared object whenever the cursor moves. Sometimes, something in
between immediate updates and waiting for the user to finish is required. A good
example is a shared Input Text field. The field may be part of a form that multiple
users can each contribute to filling in. Each shared Input Text field cannot be

Get Programming Flash Communication Server now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.