Home arrow Flash arrow Page 3 - More on Nonpersistent Client-Side Remote Shared Objects

More on Nonpersistent Client-Side Remote Shared Objects

Last week, we introduced you to some of the advantages of using remote shared objects in your applications. This week, in the conclusion to this two-part article, we'll apply what we learned with a few basic projects. This article is excerpted from chapter four of Learning Flash Media Server 2, an O'Reilly PDF Book. Copyright © 2008 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
January 15, 2009
  1. · More on Nonpersistent Client-Side Remote Shared Objects
  2. · Minimalist Project for Shared Function
  3. · A More Than Minimal Text Chat
  4. · A Better Chat Application

print this article

More on Nonpersistent Client-Side Remote Shared Objects - A More Than Minimal Text Chat
(Page 3 of 4 )

Now that you have an idea of how shared objects work, this next application shows how to make a pretty good text chat application. Up to this point we’ve kept it simple as far as shared objects are concerned so that you could see the basics. However, now we need to look at the shared object in a bit more detail.

The Shared Object Array

An important element of the SharedObject class associated with the onSync() event handler is the fact that the shared object is an array. As you’ve seen, you can create several slots for shared objects and these slots contain attributes with variable values. When a change to a shared object occurs and invokes the event handler, an argument can be added to an unnamed function to trap the array of objects describing the changed elements of the remote shared objects. Thus, the line,

  some_so.onSync= function(so_ObjArray) {

can capture the information in theso_ObjArray. Each object’s properties includecode,name, andoldValue. Because theso_ObjArrayis an array, you need to ferret out its elements (members). The object’s properties’codecan be set to one of the following:

Either successful connection to nonpersistent
      remote shared object or objects of a property have
      been deleted

Client changed shared object

      Unsuccessful change of shared object 

Some other client changed the shared object

Data attribute deleted

Thenamevalue contains the name of the slot. So, if you have three slots, you will have three name values in the array of objects. However, theoldValue is a bit peculiar because it only returns a value other than undefined if thecodevalue is"change".That only occurs if someone from a different client makes a change to the shared object on the same application.

To see how this works, make a few changes to the code in the minimal text chat application discussed earlier in this chapter. When you test it, you need to have two clients open at the same time. In that way you can set thecodeto"change"and see how the oldValue property is revealed. The following code should be used to replace the code in the original minimal text chat application in this chapter. Since it uses atrace()statement to display the values, run all of your tests from within the Flash test mode.

 1  //Label button components
 2  send_button.label = "Send";
 3  var rtmpGo:String;
 4  var text_so:SharedObject;
 5  rtmpGo="rtmp:/zbasicSO"
 6  //rtmpGo = "rtmp://your.domain.com/zbasicSO";
 7  var nc:NetConnection = new NetConnection();
 8  nc.connect(rtmpGo);
 9  text_so = SharedObject.getRemote("sharedtext", nc.uri, false);
10  text_so.onSync = function(list) {
11      for (var i = 0; i<list.length; i++) {
12          trace(list[i].code)
13          trace(list[i].name)
14          trace(list[i].oldValue)
15         if (text_so.data.textValue != undefined) {
16             _level0.chat_txt.text += text_so.data.textValue;
17        }
18    }
19 };
20  text_so.connect(nc);
21 //Send remote shared object
22 var sender:Object = new Object();
23  sender.click = function() {
24     text_so.data.textValue = message_txt.text+newline;
25 };
26 send_button.addEventListener("click", sender);


You will notice that when you enter text on your “local” client, the Output window shows “undefined” for theoldValue. However, when you enter text on your “remote” chat, you will find that the Output windows shows whatever the previous value was.

blog comments powered by Disqus

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials