| By Michael Labriola | Article Rating: |
|
| March 1, 2006 05:00 PM EST | Reads: |
21,468 |
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.
Published March 1, 2006 Reads 21,468
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
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.
![]() |
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. |
||||
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF





























