Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Using Runtime Shared Libraries
Improving download performance

With Macromedia Flex 1.5 you can build runtime shared libraries (RSLs) that can be individually loaded, cached, and used by multiple applications. This article demonstrates how easily you can integrate RSLs into your Flex applications. It also addresses the performance tradeoffs that you must consider when building dynamically linked applications.

The Basics
The best way for you to learn about RSLs is to build several copies of the same application with and without various permutations of RSL settings. Follow these steps:

1.  Create Info.mxml, a small MXML component that displays its initialization time:

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Button xmlns:mx="http://www.macromedia.com/2003/mxml"
backgroundColor="#ffffff"
width="250" height="150"
initialize="go()">
<mx:Script>
var name:String = "?";
function go()
{
var start:Number = 0;
if (_global.startTime != undefined)
start = _global.startTime;

var dt:Number = (getTimer() - start) / 1000;
label = name + " initialized in " + dt + " s." ;
}
</mx:Script>
</mx:Button>

2.  Create app1.mxml, a trivial little application that you use as the basis for the experiments:

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*"
width="300" height="200">
<Info name="{className}" />
</mx:Application>

3.  Load app1.mxml in your browser. You will see a button similar to Figure 1.

Figure 1. Browsing app1.mxml, a simple Flex application

The size of the generated SWF file is fairly large, because simply using the Application and Button classes causes much of the Flex application model to be linked into your application. If you have the <keep-generated-swfs> option enabled in your Flex configuration file, Flex writes a copy of the SWF file to the application directory as app1.swf (not to be confused with the URL used to download the SWF file, which is actually app1.mxml.swf):

% ls -l app1.swf
-rw------- 1 rg 129899 Oct 18 07:14 app1.swf

Each Flex application starts from a similar baseline size, because each contains most of the same components. Clearly, if you have multiple Flex applications on your server, it is wasteful (of users time and your bandwidth) for users to have to download so much redundant information!

Wouldn't it be nice to factor shared components and assets in your application into libraries that could be loaded at runtime? You can!

The following steps show you how to convert your baseline application to use RSLs: #1  Specify what goes into the library. Create a file named shared.sws with the following content:

<library>
<component name="Application"
uri="http://www.macromedia.com/2003/mxml" />
<component name="Info" uri="*" />
</library>

#2  Copy app1.mxml to app2.mxml. Edit app2.mxml to look like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*"
width="300" height="200"
rsl="shared.sws">
<Info name="{className}" />
</mx:Application>

#3  Load app2.mxml in your browser, and if you haven't made any typos, it should look virtually identical to app1 (Figure 1).

Congratulations, you've now converted a statically linked Flex application (all components and assets defined internally) to a dynamically linked Flex application (some components and assets loaded at runtime). Observe the file sizes:

-rw-------  1 rg    129899 Oct 18 07:14 app1.swf
-rw-------  1 rg    9127 Oct 18 07:23 app2.swf

You've decreased the SWF file size by 117K - quite an improvement! I'll explain where the bits went in the next section. On the surface, it might appear from your SWS file that you were only going to import the Application and Button components. However, you are actually also importing all their dependencies. In general, you will see an immediate improvement in download size by building a SWS file that just references Application, but you get the best improvement by carefully setting up your SWS specification to include all referenced shared components.

Currently, there is no straightforward way to know the optimal set of components to include in your SWS file. However, you can get some hints by perusing the compile report generated when you build your application (and have the appropriate setting enabled in your Flex server configuration file). Any symbol definition marked "external" is imported from a RSL. All other symbols are linked into the application itself. Don't worry too much if a few stray classes get linked in; if you just list the MXML elements that you use, you are guaranteed to get a highly effective RSL.

About Roger Gonzalez
Roger Gonzalez is a Principal Engineer on the Flex compiler team. Prior to Macromedia, he has done everything from working on autonomous underwater robots to running the engineering group at a 3D game development studio. Roger is an avid motorcyclist, and recently relocated to California in order to pursue year-round riding.

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

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
As a result, it said, of “customer feedback and evolving usage patterns,” Microsoft cut the price of its cloud-ified SQL Azure database 48%–75% for databases larger than 1GB and introduced a new entry-level 100MB model. It blogged that it’s noticed that many projects start smal...
Wide and cheap availability of cloud-based media services is upon us. With the transformations these services are already bringing to the consumption of music, video and interactive media, change has likewise come to professional workflows. Documents in 2012 are read, written, co...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical ...
Fresh off a happy quarter, Rackspace said Thursday that it’s bought SharePoint911, one of those you-never-heard-of-them outfits that does SharePoint consulting, training and JumpStart services so it can deliver newfangled SharePoint services along with its existing SharePoint hos...
Cloud is a shift from the focus on underlying technology implementation to leveraging existing implementations and further building upon them. Cloud orchestration or a network of clouds is the wave of the future where these clouds can operate with elasticity, scalability, and eff...
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