Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: Adobe Flex

Adobe Flex: Article

Integrating Remote Shared Objects with Flex and Flash Communication Server

In this project, a remote shared object on a Flash Communication Server contains data that changes frequently

Example 2: flexFCS_02.mxml (additions are highlighted) <?xml version="1.0"
encoding="utf-8"?> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*" creationComplete="initializeApplication( event )">

<mx:Script>
<![CDATA[
var myData:Array;
function initializeApplication( event )
{
//We are called by the creation complete event of the application tag
//Instantiate a new Array
myData = new Array();

//Connect to the flash communication server.
//we are using rtmp as our first protocol attempt
my_fcs.connect(Œrtmp://[your_server]/random');
}

]]>

</mx:Script>

<mx:DataGrid id="display_grid" dataProvider="{myData}" width="90%" height="90%"/>

<!--Created a DataGrid and bound the dataProvider to myData-->
<!--Instantiate an FCSService component-->
<FCSService id="my_fcs"
closed=" alert( Œserver closed connection' )"
rejected=" alert(ŒServer rejected connection')"
failed=" alert(ŒServer connection failed')" />

<!--Instantiate an SharedRemote component and bind it to the FCSService tag
above-->

<!--The name property of this tag must match the argument in the SharedObject.get
command on the server file main.asc-->

<SharedRemote id="my_remote1"
name="RandomNumbers"
service="{my_fcs}"
failed="alert(ŒShared Object Failed')"
status="alert(ŒStatus Œ + event.info.level + Œ Œ + event.info.code );"/>
</mx:Application>

In this version, I added three important blocks of code:

  • An FCSService component
  • A SharedRemote component
  • A call to the FCSService object's connect method
First, examine the FCSService component. The FCSService has an id of my_fcs, which you use to reference the instance going forward. You also defined event handlers for the closed, rejected, and failed events. If an end user encounters any type of problem, an alert box will display.

Second, the SharedRemote component has an id of my_remote1. The service property is set to {my_fcs}, the id of the FCSService component. This allows any FCSService component to have multiple shared remote objects defined. The SharedRemote component also defines event handlers for the failed and status messages. If an end user encounters a problem with the shared object, an alert box displays on the screen.

Finally, the initializeApplication handler calls my_fcs.connect(Œrtmp://yourServerName/random' ). The name, random, is the name of the application created when you placed the main.asc file into the random folder on your FCS.

When you invoke the connect method, you attempt to make a connection initially through RTMP to FCS. In reality, you actually have several protocols/port combinations which will be tried before a connection occurs. While this concept is outside the scope of this article, please read "Tunneling Macromedia Flash Communications Through Firewalls and Proxy Servers" for more information.

If you run the application at this point, you will see a DataGrid, much like the previous example.

If an alert box appears, ensure that your Flash Communication Server is running and that you placed the main.asc file in the proper directory as explained in the "Flash Communication Server" section.

The Good Stuff
After the last round of revisions, your application can receive updates from the server, but can't do anything with them yet. Now you'll add that functionality.

Add the highlighted code below to Example 2 (flexFCS_02.mxml) or, open the solution file, flexFCS_03.mxml, which contains all of the changes. The flexFCS_03.mxml file is included in the fcs_flex_sample.zip that you downloaded in the Requirements section of this article.

More Stories By Michael Labriola

Michael Labriola is a founding partner and senior consultant at Digital Primates IT Consulting Group. Digital Primates analyzes client business processes and develops custom solutions that extend the latest technology.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
SYS-CON Italy News Desk 03/01/06 06:11:57 PM EST

Communication Server (FCS) together provide an amazing toolbox that will undoubtedly provide inspiration to thousands of developers and projects. Unfortunately, without concrete examples and guidelines for good practices on their integration, we spent many hours on tiny issues that, with additional information, could have been easily circumnavigated.