Comments
Patrick Collands wrote: collands (AT) gmail com I'd be very grateful for an invitation. Thank you.
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..

SYS-CON.TV
Today's Top SOA Links


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 3: flexFCS_03.mxml (additions shown in bold):
<?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');
}
function syncData( event )
{
var currentIndex:Number;
var currentNode:Object;
for ( var i=0; i<event.actions.length; i++ ) {

/* This is cheap and cannot be relied upon, however, for this example: our slot 'names' are all
numeric and can be used as Indexes into the array.These names are set when we do the
random_so.setProperty("0", ... ); in the main.asc file.The "0" is the slot name So, in this
case the slots are named 0,1,2,3 and so on. */
currentNode = event.actions[i];
/* Whenever we receive a synchronization event from FCS, it is provided as an
array.Each element in the array has a code, which defines the type of event we are
receiving. In this case, we are only looking at two of the possibilities, a slot changed or
the whole array should be cleared */ switch (currentNode.code)
{
case "change" :
//This slot has changed and needs to be
//updated

if ( myData[ currentNode.name ] == undefined )
{ //Even though FCS sees this data as
//a change, this is the first time we have
//data in the slot
//So we add it to our data structure
myData.addItemAt( currentNode.name,
{ label:event.data[ currentNode.name ].label,
value:event.data[ currentNode.name ].value } );
//Notice above that we are using the { } as a shortcut to create a new object from the
data we received from FCS
//This is do to the databinding properties of flex.
//If we do not create a copy of the object, flex will try to update FCS server
everytime we make a change to the object
//This can be desireable, but, it is not for this example
}
else
{
//We have seen data for this slot before, so we update our data structure
myData.replaceItemAt( currentNode.name,
{ label:event.data[ currentNode.name ].label,
value:event.data[ currentNode.name ].value } );
}
break;
case "clear" :
//FCS has instructed us to clear all of our existing data
myData.removeAll();
break;
}
}
}
]]>
</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 );"
sync="syncData( event )"/>
</mx:Application>

In this version, you added two important items. You specify an event handler for the sync event of the SharedRemote component and added the code for that handler.

First, let's talk about the syncData function. This is the function that performs all of the work in preparing the data for display. The event object passed to this function always contains two very important properties: actions and data.

The actions property is an array that will contain a variable number of elements based on the changes that occurred on the Flash Communication Server. FCS adds one object to this array for every action it implements on the client. Examples of actions include: clear all of the data, delete a single element, change the value of an existing element, and so forth.

About 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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

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.


Your Feedback
SYS-CON Italy News Desk wrote: 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.
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE