Uniquely Compile AS2 with JSFL - Avoiding Class/Namespace Collision between swfs ·
3 January 2010, 22:45

AS2 does not have the concept of an application domain. So if you are loading multiple child SWFs into your AS2 project, any classes that the SWFs share will be cached at their first use. The cached definitions will stand in for any following references to the class. Not always good, and depending on your project, it can cause some pretty serious issues and headaches. Need a way around this AS2 class collision issue? Me too, so I made one.

The problem

The FlashPlayer caches classes based on their class paths/namespaces. This means it expects that all definitions of the classpath will be identical throughout FlashPlayer instance. That caching is efficient, but is not always what we want.

For example, pretend we have 2 SWFs that use the com.greenethumb.Blah class. SWF1 was made a loonnng time ago, when com.greenethumb.Blah was weak and ancient. SWF2 is new and uses the amazingly refined and optimized 2.0 version of com.greenethumb.Blah. Cool. When run independently, both swfs work and do their job. However, you have an appicaltion that loads both SWF1 and SWF2. If SWF1 loads first, it runs correctly but when SWF2 loads, OH NO, it can’t use it new fancy version of com.greenethumb.Blah because the FlashPlayer has cached SWF1’s version and is forcing it on SWF2! Wouldn’t it be nice to allow the SWFs to use the class definitions they were compiled with?!

The goal

We want to easily compile our AS2 swfs without worrying that incremental changes to your source files will break other swfs in our project, or require us to retrofit our other swfs to work with the modified code.

The hard way

It SOO simple let’s just:

The easy way

I prefer to make my computer handle such automated stuff. I wrote a JSFL script to handle all this stuff for me.

The script

Here is a zip with the JSFL script and example FLAs . Happy compiling…. Well, as happy as you can be working with AS2…


Jonathan Greene

comments:

  1. Erm… “JSFL”?

    Walker Hamilton · Jan 4, 04:32 PM · #

  2. Javascript for the Flash IDE. Its kinda like writing automator scripts or photoshop actions for the Flash IDE… except you write it all by hand :)

    Jonathan Greene · Jan 4, 04:58 PM · #

Name
Email
Website
Message
  Textile Help