Tom Lauck’s Deseloper.org

Pre-Caching Flex Applications Using YUI

author: tom

I thought a little scenario might assist in prefacing this post.Bob has built a cool Flex application and it now time to show it off to the world. Bob is a web guy, so like most web guys, he uses YSlow to see the performance on his pages. Flex application and YSlow in hand, Bob uploads his files to his web-server. He then realizes that he forgot to ask himself one very important thing, “how big is this Flex application anyway?” To Bob’s dismay, the final size is almost 2 mb! Bob has some options:

  1. Not caring - he has some decency.
  2. Revisit code - he has a deadline to meet.
  3. Play around with RSLs - now he’s getting on the right track.
  4. Pre-caching the application - getting warmer.
  5. Pre-caching the application and the Flex framework - tada.

Now back to me…Bob’s best options here are 3, 4, 5. And more specifically 3 and 5. If you aren’t familiar with RSLs (Runtime Shared Libraries) in Flex, I highly recommend them. By implementing RSLs, it becomes possible to cut down the initial file size of the application, only loading libraries when needed.But one still has to load the swf libraries, even if RSLs are utilized. In many scenarios users visit a specific page or URI before accessing or launching a Flex application. For instance, a search page followed by Flex search results. To take advantage of this, why not take employ AJAX? After all, its primary purpose is the asynchronous transmission of data, so AJAX seems like the perfect tool for the job.I chose YUI for this example, but you could use jQuery or something of the like.

//Caching methods using YUI
var flashCache = {
	handleSuccess:function(o)
	{
		this.processResult(o);
	},
	handleFailure:function(o){ },
	processResult:function(o){ },
	startRequest:function(url) {
		YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
	}
};
var callback = {
	success:flashCache.handleSuccess,
	failure:flashCache.handleFailure,
	scope: flashCache
};

//Cache the swf and swz
window.onload = function()
{
	flashCache.startRequest("flexApplicaiton.swf");
	flashCache.startRequest("framework_3.0.189825.swf");
	flashCache.startRequest("framework_3.0.189825.swz");
};

By asynchronously loading the Flex application, Framework while the user is taking a preliminary action, you basically take the 2 mb Flex application (although hopefully it is less because you are using Runtime Shared Libraries) and turn it into 12-40k. Otherwise known as the size of the page which the swf file is embedded. (The photo below is not a real representation of the scenario, but illustrates the difference in cache.)

YUI Cache

It is understood that most users who visit your site have an empty cache. However, if you have instances where the user will spend some significant amount of time (enough to load the swf), you and Bob (from the outset) can rejoice in the now optimized speed and total score benchmark you will receive in YSlow…2 mb Flex application included.

Mar 19 2008

Modest Maps: Yahoo Style Flex Component Markers

author: tom

View example and download source.

History

Creating software with mapping should be a figurative walk in the park given the tools available from the major map api players like Google and Yahoo. However, when creating software on the Flash platform that needed mapping, my immediate choice was to go with Yahoo, since they have a history of being Flash friendly.

After investigating and implementing the examples Yahoo providing using the ASTRA Web Api, and in the end the solution as a whole seemed to work, albeit not as robust or simple as I would have liked. All was apparently well until production time. Once I deployed to the web, with a DOCTYPE of xhtml-transitional, the map ceased to dispatch the onMapLoad event.

As an alternate AS3/Flex solution I discovered Modest Maps. The hitch was that using Modest Maps would require building custom own components (such as Zoom, Map Types, Markers, Etc), for modest maps displays the map only.

Solution

I really take a liking Yahoo’s map markers. There was a hitch, Modest Maps was written in AS3 only. Therefore, when I went to integrate a Flex based marker into the map, the two were incompatable.

My solution:

  • Reworked the Modest Maps core to use FlexSprite and UIComponent (which inherits FlexSprite).
    • As a site note: I’m not sure that was completely necessary and would have rather not touched the core, but I was in get’er done mode.
  • Built a marker that looked an functioned like Yahoo’s, with the ability to add any flex component inside.
  • Created some events that bubble up when the user clicks inside the marker.
  • Created functionality to open a selected marker, based on its Id.

I see my work as a mere starting point. As Google states, “release early, release often.” So, please view the example, download the source and play. I would love to see where things go with it, if any.

Jan 1 2008

Test Drive with Adobe’s PHP RIA SDK

author: tom

A couple weeks ago, in response to a Flex tip I posted, Mike Potter from Adobe commented and left a link to his Google Group for the PHP RIA SDK. Having worked with Flex and AMFPHP, I found this SDK quite interesting. I noted that it had various basic/core examples that give a nice start when beginning your application. Included are examples using the Flex/AJAX Bridge, PHP/XML/Flex, AMFPHP, and (my new favorite) WebOrb.

It can be downloaded, here (2.5M zip).

Of course, you will probably end up making your *own* SDK, but I thought this was a good foundation, especially given the fact that it includes two different remoting options with sample services. From there, you can pretty much do anything. Additionally, now that Flex has been made available for Mac (Beta), workflows can become even quicker.

Nov 29 2006

Flex AMFPHP Variables

author: tom

Working with XML in AS2 is to say the least, one of the dumbest and most redundant things in the world to me. Because of this, I use Flash Remoting. It just makes more sense. So when I moved on to Flex, even though XML is native in AS3, I still went with remoting. Mike Potter from Adobe had a basic tutorial on getting started with Remoting in Flex…for it is a little differnent from Flash. And those differences can really throw you, and leave yourself cursing at your own stupidity.

Here was my issue: Everything was going fine with my development, and I was falling even more in love with Flex and then all of a sudden, variables were not getting passed when I started debugging. Huh? So to make a long story short, the syntax for passing variables in Flex is a little different from the the standard/basic AMFPHP structure:

Rather than something like this:

public function getAllPages(){
	gateway = new RemotingConnection("http://localhost/flashservices/gateway.php");
	gateway.call( "SitePages.getAllPages(php_variable)", new Responder(handleGetAllPages, onFault));
}

Notice the placement of the variable “php_variable” above.

You do something like this:

public function getAllPages(){
	gateway = new RemotingConnection("http://localhost/flashservices/gateway.php");
	gateway.call("SitePages.getAllPages", new Responder(handleGetAllPages, onFault), php_variable);
}

Oct 31 2006