
The other day I was writing the code for a simple animated movie. I decided to use a host flash to get the user started quickly and then create a separate SWF file for each scene in the movie. The host flash would then preload the next scene while the current one was playing. MovieHost.as would be the document class for the host movie and Scene.as document class for all the scenes. Simple right? Budget: 6-7 hours including the stop frame animations…
Well, not quite so. I created all the animations in all the swiffs, set up the hos flash to load them in, pressed command+enter to verify my effectiveness. The host flash fires up and loads the first scene but the scene’s code does not seem to run at all. And no error messages? After all this is AS3 – WTF??
I won’t bore you with the details of all my testing, but it went to the point where I started to research the use of explicit application domains and such. After some hours I found the reason, and here it it:
From the Flash documentation on the ApplicationDomain class:
“You cannot override a loaded class definition with a newer definition.”
This says it all really. Close to the top of my HostMovie.as class (where I hadn’t been for a while) I found this line:
private var _currentScene:Scene;
Even though this variable was not being used in any way, the host flash still had a compiled version of the class Scene.as when the scene swiffs were being loaded. I f you look at the comment from the documentation again you realize that of course no code from the loaded swf could run, it’s document class had been discarded in favor of the one allready existing in the host flash.
I removed the unused property definition from HostMovie.as and everything from there on went as planned.