Flash
  Home arrow Flash arrow Page 3 - Nonpersistent Client-Side Remote Shared Ob...
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

Nonpersistent Client-Side Remote Shared Objects
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-01-08

    Table of Contents:
  • Nonpersistent Client-Side Remote Shared Objects
  • Instantiating Remote Shared Objects
  • Inspecting a Shared Object
  • Minimalist Project for Shared Movie Clip

  • 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


    Nonpersistent Client-Side Remote Shared Objects - Inspecting a Shared Object


    (Page 3 of 4 )

    To get a better idea of what’s going on in a shared object, you can look at the contents something like you’d look at the contents of an array or other object that has more than a single element. Add a folder to your server-side folders named zbasicSO. (This folder will be used for all of the examples in this chapter.)

    In the following example, several different types of data are added to the slots. I’ve used literals as well as variables to illustrate the range of data that can be put into shared objects. Just open up a new Flash document and enter the following code in the Actions panel:

     1 //Connect
     2 var rtmpNow = "rtmp:/zbasicSO";
     3 //var rtmpNow = "rtmp://yourDomain.com/zbasicSO";
     4  var nc:NetConnection = new NetConnection();
     
    5 nc.onStatus = function(info) {
     6     trace(info.code);
     
    7 };
     
    8 nc.connect(rtmpNow);
     
    9 //Shared object
    10  var test_so:SharedObject = SharedObject.getRemote("test", nc.uri, false);
    11  var rightNow:Date = new Date();12 //Begin list of slots
    13  test_so.data.dayOfMonth = rightNow.getDate()
    14 test_so.data.money = "$100";
    15 test_so.data.verity = true;
    16 test_so.data.bunch = 250;
    17  //End list of slots
    18 for (var attribute in test_so.data) {
    19     trace(attribute+" = "+test_so.data[attribute]);
    20  }

    When you run the script, your Output window should show something like the following (without the parenthetical comments and, unless you are testing this on the 27th of the month, yourdayOfMonthvalue will differ):

      bunch = 250(Number)
     
    verity = true(Boolean)
     
    money = $100(String)
     
    dayOfMonth = 27(Date)
      NetConnection.Connect.Success

    As you can see, shared objects take on the basic data types in ActionScript, and they can be extracted in the same way other objects and variables can be.

    Syncing Shared Objects

    Whenever the value of any shared object property attribute, or “slot,” changes, that change must be broadcast to all of those connected. The event handler for this process isSharedObject.onSync(). Each time any data attribute changes, a change event triggersSharedObject.onSync()and in this way, all of the changed attributes in all of the connections are updated. The general format is the following:

      my_so.onSync = function(myArrayList){
          //Update variables with so.data property attribute values
          variable1= my_so.data.attribute1;
          variable2= my_so.data.attribute2;
          variable3= my_so.data.attribute3;
      }

    The process for this change is pretty straightforward. Somewhere in the script a user makes a change to one of the slots in the shared objectdata property. As soon as that property is changed, it triggers theSharedObject.onSync()and when that happens, the code in theSharedObject.onSync()container updates the changes throughout the connections in the application.

    In order for the whole process to work correctly, you need to call
    SharedObject.connect(NetConnection). So to work with remote shared objects meaningfully, you will need a line that connects the shared object instance to FMS2 using theNetConnectioninstance as a parameter. For example:

      billz_so.connect(nc);

    makes the necessary connection for the shared object instancebillz_soto send and receive the changes to shared objects using theNetConnectioninstancenc. In all of the sample projects in this chapter, keep an eye out for the
    SharedObject.connect(NetConnection) statement, and don’t ever forget to include it in your applications. (When you debug your code, often you will find that the shared object connection has been left out, and your shared objects will not run correctly without it.)

    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 1 Hosted by Hostway
    Stay green...Green IT