MACROMEDIA FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY Spécifications Page 160

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 369
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 159
Chapter 482
Assign an owner
A more complex strategy is to define a single client as the owner of a property
in a shared object for a limited period of time. You might write server code to create a “lock
object, where a client can request ownership of a slot. If the server reports that the request was
successful, the client knows that it will be the only client changing the data in the shared object.
Heres some server-side ActionScript that locks and unlocks a shared object to make sure the true
highest score is returned to the game. Suppose the most recent highest score was 95, and player 1’s
score increased to 105, while player 2’s score increased to 110. If no locking occurred, both
players’ scores could be compared to the most recent highest score, 95, or a collision could take
place if both clients call
updateHighScore simultaneously. Youd want to make sure that each
player was compared to the highest score, regardless of whether it was the most recent highest
score or any score currently coming in from all other clients. If you lock and unlock the shared
object used to store the highest score, you can compare each score sequentially, and thus ensure
that no comparison is lost.
application.onAppStart = function()
{
application.scoreSO = SharedObject.get("high_score_so", true);
application.scoreSO.onSync = function(listVal)
{
trace("got an onSync on scoreSO");
}
}
application.onConnect = function(newClient,name,passwd)
{
newClient.updateHighScore = function(final_score)
{
application.scoreSO.lock();
if (application.scoreSO.getProperty("high_score_so") < final_score)
{
application.scoreSO.setProperty("high_score_so", final_score);
}
application.scoreSO.unlock();
}
}
Notify the client When the server rejects a client-requested change to a property of the shared
object, the SharedObject.onSync event handler notifies the client that the change was rejected.
Thus, an application can provide a user interface to let a user resolve the conflict. This technique
works best if data is changed infrequently, as in a shared address book. If a synchronization
conflict occurs, the user can decide whether to accept or reject the change.
Accept some changes and reject others Some applications can accept changes on a “first come,
first served” basis. This works best when users can resolve conflicts by reapplying a change if
someone elses change preceded theirs.
Use the send method to increase your level of control over changes to objects Rather than
relying completely on
SharedObject.onSync to manage synchronization activities, use the
SharedObject.send command as appropriate. The SharedObject.send command broadcasts
a message to all clients connected to a remote shared object, including the client that sent the
message.
Vue de la page 159
1 2 ... 155 156 157 158 159 160 161 162 163 164 165 ... 368 369

Commentaires sur ces manuels

Pas de commentaire