Controlling Flash Player 8 SWFs in Flash Player 9 SWFs

One of the things I’ve been promoting the last year is encouraging people not to mess with loading legacy Flash Player 8 content into Flash Player 9, usually with regards to Flex 2 content loading Flash 8 content.

ExternalInterface gives you less browser support, the calls are blocking which locks up your visual display depending on speed, and causes security debugging challenges if you don’t know exactly what you are doing. The last is the kicker because you DON’T have to know, you just know it works, and you move on. When under a deadline crunch with a boss yelling at you, it’s really frustrating to not know why a SWF is yelling about security rules. You don’t need another headache. LocalConnection is asynchronous, and has little strong-typing, and has a limit on the size of messages you can send. Furthermore, you have no guarantee every call you make will… make it. There have been abstraction attempts which really end up with about the same amount of code had you not abstracted it.

Bottom line, it’s a major headache, painful to debug, and gets really funky when you start loading multiple pre-Flash Player 9 SWF’s into the same app. My guess is, it shares the same security & application domain sandbox which you’re code is not allowed access to. Therefore, any static variables I’m guessing are stuck there too (aka, classes on _global). Never really figured out the exact reason, but it’s just blatantly crazy how bad things are and just flat out don’t work as you’d expect.

…but there is something far worse, and foreboding. Flash Player 9’s DisplayList + Garbage Collection. In Flash 8 and below, we’re pretty spoiled. We do a my_mc.removeMovieClip(), and poof, everything is gone. All sounds stop, everything stops showing, and most RAM goes with it, immediately. Not in Flash Player 9. Since you don’t have access to this AVM1Movie “sandbox”, whatever the heck it is, you can’t stop the stuff either. Case in point, load in a SWF with a video player, and then unload the SWFLoader. You’ll still hear the video, and it’ll STILL be using resources… that is, until Garbage Collection decides to nail it, if ever. In effect, Flex speaks Espanol, and Flash speaks English. You need a translator.

In the past I’d do what I’ve been doing the last 2 years; reverently exclaim you need to go to management and explain the benefits of AS3, and just rewrite your legacy content. Since I wasn’t the one who had to deal with the ramifications & implementations of those decisions, it was pretty easy for me to do so upon a high horse.

…then I started working for an Internet TV company. Thousands upon thousands of customers using Flash Player 8. Existing customers, entrenched, with working software. Boat loads of existing Flash Player 8, 7, and 6 content that works for a variety of existing customers and clients. In effect, Flash Player 8 content AND development isn’t going away for at least another year. Bugger…

I tried eating my own dog food, but you can’t just immediately demand thousands of people upgrade their rigs without incurring significant costs and losses doing so. Then I tried my best to sequester myself away from said Flash Player 8 content. No dice. The amount, and thoroughness of some of the implementations was too great for me to just re-write in AS3. I can only code so fast.

So, in the end, I’ve settled on a 3 tier setup. A Flex component that uses a SWFLoader via composition with 2 LocalConnections; 1 for talking to the SWF, and for the SWF to talk to it. A Flash Player 8, AS2 SWF that has 2 LocalConnections, 1 for talking to Flex, and another for Flex talking to it. This Flash SWF manages all content it loads, usually written for a specific piece of content. If you have control of the servers you are loading from, you can either have yourMovieClipLoader check the policy file, and boom, you’ve got no problem with loaded Flash content talking to Flash content. Even if it’s not yours, it’s very easy to dig around in someone else’s classes and “make stuff work” since everything is public in Flash Player 8 and below bytecode.

The important job of the proxy.swf is clean up the mess when you unload stuff. In the case of a Video Player, you have to stop the video, stop all sounds, and unload the player. It’s ok if the Flex component holding the proxy.swf doesn’t die immediately; the proxy.swf has basically done his job well: stopped all multimedia, and lessened the RAM & CPU damage. An ancillary benefit is you can issue commands through this proxy.swf to control your content. I just send string messages in this case and the proxy.swf knows what to do with them.

If you find yourself in this situation, don’t go down the ExternalInterface route; it’s too painful. Don’t load it using a simple Flex SWFLoader either since you’ll have no control over the content. Yes, it sucks you have to build a seperate SWF as a Mediator Pattern implementation, but if you don’t, you won’t have any control over the SWF you’re loading in. Remeber, test and get it working in Flash first before you start involving Flex in the mix.

11 Replies to “Controlling Flash Player 8 SWFs in Flash Player 9 SWFs”

  1. I may be in a similar boat though I don’t have 1000s of f8.sws… but rather one that I don’t want to re-write but do want to add a f9 only feature. I’m thinkg LocalConnection is the gateway I’ll have to use, but… what exactly is the size limit? Any info on this?

  2. Size limit is 40k for LocalConnection. Not sure what new feature you are referring to with regards to Flash Player 9. If you want full screen, you can write that in ActionScript 2 and make it forward compatible. Flash Player 9 doesn’t really have any new ‘features’ beyond full screen video that can be accessed by ActionScript 2.

  3. ouch… basically, I want to receive a bytestream of an image, fashion a bitmap data and send it to the f8 .swf

    40k could be rough if I’m chopping up an image into 40k pieces

  4. I have a Flex 2 app that contains a viewstack with about 60 ‘pages’ in the stack. Each page is a canvas with a legacy SWF on it, but they have been upgraded to AS 2.0, Flash 8. Users can navigate back and forth in the stack, like flipping pages. Problem is, once a page appears, the movie starts running, and continues even if the user goes to another page and comes back. Also, the movie will either stop, and never restart if it’s not set to loop, or will loop endlessly.

    It seemed like this would be trivial to send a start and stop command, or at least a goToAndPlay directly into the timeline of the SWF, but I can’t figure out how. I am not sure if I am running into the same problem described here, Flex is still pretty new to me. I am asking to see if someone more knowledgeable can tell me if I am dealing with the same issue before I start major re-tooling.


  5. You cannot call functions on an AVM1Movie, including simple gotoAndPlay / stop commands.

    You will need to:

    1. Update the SWF’s to support a LocalConnection so Flex can tell it to stop
    2. Have Flex send those SWF’s messages to stop when it navigates to a new page
  6. I have the same problem importing a mediaplayer built with flash8 playing flv and mp3. I was looking for one similar in Flex to begin with but the VideoDisplay and Audio support doesn’t support all I want to do.

    You have no code examples for proxy.swf and LocalConnection?

  7. Yes do you have an example of your proxy.swf, I have over 300 swf movies I need to load in a media center build with flex, but I have not control over the movies as they are in the SWFLoader I have them in now. I think I understand what you are trying to do and sound like a possible solution for me. just looking for a little extra help :-)

  8. A quick question for you. I was trying to do exactly this, load a Flash 8 swf into a Flex app and control its playback. Looks complicated and I’m more inclined to just say, for legacy content use the “old player”. My question is, how would I control the playback of a Flash 9 swf? My main goal is to playback Camtasia swfs (presumably they will update their app to product Flash 9 swfs). If I have no edit control over the swf can I still control it in Flex if the SWF is a Flash 9 swf?


Comments are closed.