views:

1262

answers:

2

Does anyone know how to take a swf (version 7) and use the SwfLoader or something similar to access a root variable in the swf from a Flex application? I have tried many things with no success. I don't want to clutter this post with all of my failed attempts, but I will post them later if I see that they are needed as examples.

Just some background: I am generating the swf file in .NET and the library I am using can only generate swfs up to version 7. The Flex app is being built with Flex 3. I need to access variables in the swf. I don't care how it is done, As long as I can do it. Doesn't matter if I am bubbling an event or using the LocalConnection or directly accessing the variables, I have had no luck doing any of that up till this point. (The swf does load though... and shows up in my Flex app).

Oh, and the swf is not embeded.

+1  A: 

ExternalInterface has been availble since as1.0, so that may be the solution to your problems. With the ExternalInterface class actionscript can communicate with javascript, and vice versa. So, you could pass a variable to a javascript function from the swf and have that javscript function pass that same variable to a function in the FLEX app. I dont want to write all the code unless this sounds like it may be the answer you are looking for, in which case let me know and I will write out the code for you, or just ...

Check it out: ExternalInterface

ForYourOwnGood
Do you think ExternalInterface (of the swf) could call a method in the Flex app directly? (If the Flex app loads the swf using SwfLoader)
Phobis
no, with ExternalInterface you will have to go through javascript first.
ForYourOwnGood
A: 

When you load a SWF that targets FP8 or earlier it is loaded as an instance of AVM1Movie. From the docs:

"The AVM1Movie object can use methods and properties inherited from the DisplayObject class (such as x , y , width , and so on). However, no interoperability (such as calling methods or using parameters) between the AVM1Movie object and AVM2 objects is allowed."

This is due to the fact that FlashPlayer 9+ actually has two different virtual machines and they are not able to communicate with each other directly.

LocalConnection will definitely work in this scenario: I've used v7 SWFs with a Flex 2 application and had communication (via method invocation) working from v7 -> Flex2 and Flex2 -> v7. I would look into how you're setting that up because it will definitely work.

cliff.meyers
examples:http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.htmlhttp://www.kirupa.com/forum/showthread.php?p=1964550
Simon Groenewolt