Loading Flex from a Flash 8 swf; Actionscript-only version checking

Not too long ago, I was poking around the internets trying to figure out how to load an Actionscript 3 (Flex) SWF file from a Flash 8-compatible (AS2) swf after version checking the player to see if it is version 9 or greater. I managed to piece together what I needed and went on my merry way.

Yesterday someone who had seen my queries on the flexcoders mailing list wrote to me to ask if I had found an actionscript-only solution after all, so I will post the solution here for future reference. I certaintly couldn’t have come up with this without tidbits from here and there…

The key to this working is not loading anything onto the stage before running this code. In fact, in my solution, I use a flash project that only does version checking and loads SWFs externally for both cases where flex is supported and where it isn’t. Insert something like the following in the first frame of your timeline and you should be all set.

var FLEX_NOT_SUPPORTED_SWF ="absolute path to a flash 8 or below swf";
var FLEX_SUPPORTED_SWF = "absolute path to a flash 9 swf";
var versionInfo = getVersionInfo(); // use your favorite implementation of this
if (versionInfo.majorVersion >= 9)

Leave a Reply

Your email address will not be published. Required fields are marked *