Home arrow Flash arrow Page 4 - Nonpersistent Client-Side Remote Shared Objects

Nonpersistent Client-Side Remote Shared Objects

If you haven't yet explored the possibilities of shared objects in applications, you're missing out on one of the more important ways to exploit the capabilities of the Internet. Keep reading to learn how you can use shared objects in your web applications. This article, the first of two parts, 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: 4 stars4 stars4 stars4 stars4 stars / 4
January 08, 2009
  1. · Nonpersistent Client-Side Remote Shared Objects
  2. · Instantiating Remote Shared Objects
  3. · Inspecting a Shared Object
  4. · Minimalist Project for Shared Movie Clip

print this article

Nonpersistent Client-Side Remote Shared Objects - Minimalist Project for Shared Movie Clip
(Page 4 of 4 )

The first minimalist project uses a movie clip as a shared object. This one shows how to set up and move a pointer. In creating applications that have online slide shows that work something like a PowerPoint presentation, you need all of the viewers to see the pointer move to the location on the screen where you want the audience to focus. Using a hitchhiker thumb as a pointer, this application has numbers in each of the stage’s four corners. The four numbers are just positions on the stage so that you can see that when you move the pointer on the screen, it will go to the same positions on all of the screens connected to the application. You’ll use these classes and objects for the application:



Movie Clip (1)

The following steps will walk you through the project:

  1. Open a new Flash document and set up the following layers, from top to bottom: Actions, MC, and Background.
  2. In the Background layer, place a number from 1 to 4 using a 48 point font in each of the four corners of the state as shown in Figure4-2. Lock the layer.
  3. Select the MC layer and draw a pointer—this can be any shape you want. (The sample in Figure 4-2 shows a hitchhiker’s thumb, but you can use a big arrow or any other pointer shape you want.)
  4. Select the shape and press F8 to open the Convert to Symbol dialog box. Select Movie Clip and click OK. Select the movie clip on the stage and provide it with the instance namepointer_mcin the Properties panel. Lock the layer. 

    Figure 4-2.  Completed stage
  5. Click on the first frame of the Actions layer and type in the following script in the Actions Panel:

     1  //Connect
     2  var rtmpNow = "rtmp:/zbasicSO";  
     3  //var rtmpNow = "rtmp://domain.name.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  pointer_so = SharedObject.getRemote("point", nc.uri, false);
    11  pointer_so.onSync = function() {
    12     pointer_mc._x = pointer_so.data.x;
    13     pointer_mc._y = pointer_so.data.y;
    14  };
    15  pointer_so.connect(nc); 16  //Control Shared Object
    17  pointer_mc.onPress=function () {
    18     this.onMouseMove = function() {
    19        pointer_so.data.x = this._x=_level0._xmouse;
    20        pointer_so.data.y = this._y=_level0._ymouse;
    21     };
    22     pointer_mc.onRelease = pointer_mc.onReleaseOutside=function () {
    23        delete this.onMouseMove; 24     };
    25  };
  6. If it does not exist already from the previous example, in the server-side FMS2 root, create a new folder and name it zbasicSO.
  7. Once you have completed the application, publish it (File > Publish). When you test it, you have to open a second window with the same application so that you can see two instances running at the same time. You will see that when you move the pointer on one screen, it also moves on the other.

Note: If you are connecting to an FMS2 server via the Internet, it’s best to upload the files to a web server to avoid running into security issues while testing.

In looking at the code, you will see that the value of the shared object is based on changes in the position of the mouse pointer. Whenever the mouse moves, both the _x and _y values of the mouse position are passed to the shared object data attributes as well as the pointer. Whenever the shared object values change, they trigger theonSyncevent handler that updates the shared object values on all of the connected clients.

Please check back next week for the conclusion to this article.

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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