Introduction
One of the benefits of the Flash Player technology is being able to write applications in the manner that best suits you. For example, you can use Flash 8 to develop high-impact animations or use Flex to build compelling business applications.
What is even better is being able to combine them together. It turns out that creating an animiation in Flash and incorporating it into a Flex application is not uncommon. And because both Flex and Flash are language driven via ActionScript, the Flex application could control the Flash animiation or vice-versa.
Doing this with Flash 8, Flash MX 2004 or Flash MX and Flex 1.5 was relatively easy. But that is not the case with Flex 2 and Flash Player 9. I’ll show how to do this and I hope you see that this is in fact, a better way to do it.
As you may know, a Flex 2 SWF requires Flash Player 9. That’s because Flex 2 uses ActionScript version 3 (AS3) and Flash Player 9 was developed (from the ground up, I’m told) to use ActionScript 3. ActionScript 3 with its stronger data typing and object-oriented structure provides a better platform for a higher performing Flash Player.
But as with all versions of the Flash Player, Flash Player 9 is backward-compatible. That is, it will run SWFs built for earlier Flash Player versions. But this happens differently than before. When the Flash Player 9 loads a SWF that uses ActionScript 2 (or less), it creates a virtual machine – a self-contained area which is loaded with the logic to run ActionScript 2 SWFs. We call this an AVM. When Flash Player 9 has loaded a Flex 2 SWF which then requests to load an AS2 SWF, that SWF is loaded into its own AVM. Thus the two SWFs run in different areas of the Flash Player. Different and isolated areas.
What this means is that your Flex 2 application cannot address the AS2 SWF and reach inside and reference its functions, variables, and timeline. Likewise, the AS2 SWF cannot get at anything in the Flex 2 application simply by referencing it.
Continue reading…