Sunday, October 12, 2008

An annoying Flash issue

While I am doing a lot of Flex development, I plan on still using Flash for the creation of animations. More importantly, my One of those Weeks series is being developed in Flash. There are only a few episodes left so there really is no point in moving that series to Flex. Flash and Flex are very similar, which is not surprising as they both produce code that is run in the Flash Player. Flex, however, is entirely driven by text files. While FlexBuilder has a graphical editor that helps you layout stuff, all the GUI work ends up being turned into an MXML file which is a text file. Graphics and other assets are separate files and can come from any tool. Flash, on the other hand, uses a binary format which embeds all the graphics. ActionScript code can be separate text files, which is what I have been doing.

When I was finishing up One of those Weeks episode 44, I came across a rather interesting bug. This was not really a bug in my code, but more of a quirk in the way that Flash handles animation. I had come across this quirk before so it didn't take me long to figure out what was going on. You see, when the player has solved the episode, there is a brief animation sequence that starts by zooming in on the background. Unfortunately, the background in this episode is scrollable by the user so the position of the background movie clip is changed by code. Flash, for some reason, does not handle hard-coded animations with symbols if that symbols location has been changed by ActionScript. The results were rather interesting, but not the ending sequence that I wanted.

Sadly, the only solutions were to use a different symbol for the animation or to do the animated sequence using ActionScript. If I was using Flex, the later approach probably would have been my approach from the outset. In Flash, though, it is easier to just create another symbol of the background and use that for the animated sequence. Actually, if I was doing this in Flex, I would have probably created a Flash .swf file that held all the assets and the end animation sequence would have just happened to be one of the assets as while Flex is much nicer for coding, Flash is way better at animation.

No comments: