Home arrow Flash arrow Page 2 - More on Nonpersistent Client-Side Remote Shared Objects
FLASH

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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

More on Nonpersistent Client-Side Remote Shared Objects - Minimalist Project for Shared Function
(Page 2 of 4 )

This next little minimalist project is very cool. It allows you to open a web page on someone else’s browser. You can open up a web page from any domain, not just your local one. Here are the classes and objects you’ll use:

Classes
  
NetConnection

   SharedObject

Objects
  
TextInput Component (1)

   Button Component (1)

In setting up a link to another URL, ActionScript employs thegetURL(url)function. Because the function’s argument is the string with the URL, the argument will be the shared object. Figure 4-4 shows a chunk of code from the project that traces the changing of the shared object to the firing of the function. The three key elements are numbered from 1 to 3.

In step 1, a function is defined that includes a shared object data attribute in the definition. In step 2, an unnamed function (webPageobject) assigns the shared object a new value when the user presses a button and fills in an InputText component. In step 3, the change in the shared object triggers theSharedObject.onSyncfunction that contains thegetURL(url)function. Thus, all connections open up the same web page. Use Figure 4-5 as a guide and use the following steps to create the full application:


Figure 4-4.  Path of shared object events


Figure 4-5.  Objects and instant names

  1. Open up a new Flash document and set up the following layers, from top to bottom: Actions, Text Input Component, Button, and Label.
  2. In the Text Input Component layer, add a TextInput component and provide it with the instance nameurl_ti.
  3. Add a button to the Button layer and give it the instance nameurl_button.
  4. Add the label Enter URL Name (without http://) using static text on the Label layer. Add a logo in the upper left corner. 
  5. Click the first frame of the Actions layer and add the following script:

      1  var rtmpNow:String;
     2  rtmpNow="rtmp:/zbasicSO"; 
     3  //rtmpNow = "rtmp://192.168.0.11/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 webpg_so:SharedObject = SharedObject.getRemote("showWeb", nc.uri, false);
    11 webpg_so.onSync = function() {
    12     showURL(webpg_so.data.urlName); 13 };
    14 webpg_so.connect(nc);
    15 //Open URL
    16 var defaultURL:String = "
    www.sandlight.com";
    17 url_ti.text = defaultURL;
    18 url_button.label = "Show Web Page"; 19 showURL = function (urlNow) {
    20     if (urlNow) {
    21        getURL("
    http://"+webpg_so.data.urlName,"_blank"); 22     }
    23 };
    24 var webPage:Object = new Object(); 25 webPage.click = function() {
    26         webpg_so.data.urlName = url_ti.text;
    27         url_ti.text = "";
    28 };
    29 url_button.addEventListener("click",webPage);

When you run the program on a single machine with two instances, you will get two of everything, but run with two or more computers, you will see a web page appear for all your connections.


blog comments powered by Disqus
FLASH ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials