Home arrow Flash arrow 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
(Page 1 of 4 )

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.



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

  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.

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-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials