views:

437

answers:

3

I currently maintain an application that's written in Flash 8 (AS2) which is used to embed and control some auto-generated SWFs. The auto-generated SWFs are also Flash 8 (actually, they work at least in 7, possibly even older), so my current app is able to directly reference variables and functions within the embedded SWF.

We're now working on a new version of this application, written in Flex. We need to duplicate the current app's functionality of embedding and controlling the auto-generated AS2 SWFs. However, AS3-based SWFs can't reference variables or functions within an embedded AS2-based SWF. Unfortunately we don't have control over the auto-generation tool, so we can't change that to output AS3-based SWFs.

The only real solution to getting the AS3 and AS2 SWFs to communicate is to use LocalConnection. I'd need to create a wrapper AS2 SWF that would load the auto-generated SWF and act as a proxy, communicating with my Flex app via LocalConnection and doing whatever needs to be done to the auto-generated SWF. However, there's a problem with this. The proxy SWF needs to know what LocalConnection ID to use, but I can't find a way to communicate the ID to it (I can't just hard-code some random ID as I need to be able to support multiple instances of this app simultaneously).

Has anyone solved this? Is there any way to get some kind of unique identifier to the embedded SWF?

A: 

Could the two communicate through a server (i.e. a mediator)?

Assaf Lavie
That's what I'm thinking about, but I still need some way to identify which instance it is. I have an idea that might work, but need to investigate it a bit more.
Herms
+2  A: 

Not sure I get exactly how the application works so excuse me if I'm wrong. If the flex instance must load the AVM1 proxy wouldn't it be possible to inject a flash-var via the URL containing a generated ID for the LocalConnection to use ?

In addition to your comment, just added how to send variables to the AVM1 movie. This works fine locally at least (not tested on network):

AS3 - FP10:

loader = new Loader();

var request:URLRequest = new URLRequest("as2proxy.swf");
var variables:URLVariables = new URLVariables();
variables.id = "local_connection_id";
request.data = variables;

loader.load(request);

AS2 - FP7 (first frame on the timeline of "as2proxy.swf") :

trace(id); // (_root.id)

BTW, stumbled on the following class from Libspark : http://www.libspark.org/svn/as3/ForcibleLoader/src/org/libspark/utils/ForcibleLoader.as

Theo.T
Can the FlashVars be embedded within the URL? If they can then that would work great, but I didn't think that was possible. Does Flash automatically handle that?
Herms
I'm not sure I'm seeing the use of that class you linked. I mostly see what it's doing, but I'm not seeing the reason for it.
Herms
so URL query params in the URL are treated as flashvars? I'll have to try that out. Thanks!
Herms
Well, I was getting weird errors trying to actually display the AS2 content, but I was probably just doing something dumb. Passing values in the URL worked great!
Herms
A: 

Here's a fairly involved article on the subject of communicating across the AVM boundaries:

http://asserttrue.com/articles/2006/05/16/library-type-assets-in-actionscript-3-0-using-assets-created-with-current-releases-of-flash-authoring

Luke Bayes