Flash
  Home arrow Flash arrow Page 3 - More on Nonpersistent Client-Side Remote S...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

More on Nonpersistent Client-Side Remote Shared Objects
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2009-01-15

    Table of Contents:
  • More on Nonpersistent Client-Side Remote Shared Objects
  • Minimalist Project for Shared Function
  • A More Than Minimal Text Chat
  • A Better Chat Application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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:

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

    success
      
    Client changed shared object

    reject
          Unsuccessful change of shared object 

    change
      
    Some other client changed the shared object

    delete
      
    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.

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Learning Flash Media Server 2, an O'Reilly...
     

    FLASH ARTICLES

    - 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
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek