Flash
  Home arrow Flash arrow 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


    (Page 1 of 4 )

    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.

    Minimalist Project for Shared Text

    Having seen a minimalist project for a movie clip, we’ll now look at one for sharing text. The concepts are essentially the same, but instead of basing the changes in the shared object slots on the movement of the mouse position on the stage, the changes are based on typed input by the user.

    In this application, the user changes the value of the shared object property attribute (text content) by typing in the value and pressing a button to fire a function. The function enters the value of the text input field and assigns that value to the shared object attribute. Here are the basic elements of the project.

    Classes
       
    NetConnection

      SharedObject

     Objects
      
    Dynamic Text Field (1)

       Input Text field (1)

       Button Component (1)

    Follow these steps to create the application:

    1. In the server-side FMS2 root, create a new folder and name it zbasicSO. (This is the same server-side folder used in all of the applications in this chapter, and if you have it in place already, you don’t have to add another one.)
    2. Open a new Flash document and set up the following layers, from top to bottom: Actions, Text Fields, Button, and Label. Lock the layers.
    3. Unlock the Text Fields layer and add a large, multiline dynamic text field, and below it add a single line input text field. Use Figure 4-3 as a guide. In the Properties panel, enter the instance namechat_txtfor the large text field and message_txtfor the small text field. Check the “Show border around text” property for both text fields. Lock the layer.
    4. Unlock the Button layer and add a button beneath the smaller of the two text fields. Provide the button with the instance namesend_button. It will be used to trigger the change in the shared object. Lock the layer.
    5. In the Label layer, use static text to add a label across the top of the application. Figure 4-3 shows the label used in this example.


      Figure 4-3.  Text fields, and instance names
    6. Lock all the layers, click on the first frame of the Actions layer, and add the following script: 

       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://domain.name.com/zbasicSO";
       7  var nc:NetConnection = new NetConnection();
       8  nc.connect(rtmpGo);
       9  //Set up shared object
      10  text_so = SharedObject.getRemote("sharedtext", nc.uri, false);
      11  text_so.connect(nc);
      12  text_so.onSync = function() {
      13      if (text_so.data.textValue != undefined) {
      14         _level0.chat_txt.text += text_so.data.textValue;
      15      }
      16  };
      17  //Send remote shared object
      18  var sender:Object = new Object(); 19  sender.click = function() {
      20    text_so.data.textValue = message_txt.text+newline;
      21     message_txt.text = "";
      22  };
      23 send_button.addEventListener("click", sender);

    When you test this application, you will need to run two copies of it. Even though it’s a minimum application, it’s perfectly functional and you could chat with others all day long with this little app. Just remember this sequence when coding chat
    applications:

    1. Change value of shared object property attribute (e.g., text content) 
    2. TriggerSharedObject.onSyncfunction 
    3. Change local properties with shared object value within the function

    When you look at client-side shared objects as a simple sequence, it’s not so hard to see how they are set up in a script.

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