AS3: Communication between Flash 9 SWFs
Yesterday someone asked in Flashkit for a method to use assets from library hosting inside an external loaded SWF. It’s a question about communication between Flash 9 (AS3) SWFs actually.
As I don’t have a robust debugger for Flash 9 Alpha, what I talk here is just one of the method today I could use to communicate between AS 3 SWFs. It might easier to find more methods after Flash CS3 offically released in spring 2007.
In AS2, we can use _level0, _level1, and so forth, they pointed to different SWFs, so we can call them without any problem. But in AS3 it’s different (at least right now I couldn’t get similar idea from Flash 9 Alpha debugger panel.) . But I found a way to communicate each other easily. (I call here the main AS3 SWF is the _main one, and loaded AS3 SWF is a _sub one.)
The only connection I know right now from Flash 9 Alpha, is the median Sprite, for _main it’s the .content loaded, for _sub it’s the root, they’re the same object indeed. So the simplest way to communcate between _main and _sub, we can call functions through it. If we want to call something from _sub, we can call root.parent.somefunction() to do something. From another side, we call from _main with .content.somefunction() as well.
So I suggested him to call a function inside his external swf to create a new instance of the asset and return the reference back to main stage, thus he can addChild it anywhere. And it worked. Cool!

























Show.Key.Jar said
am May 23 2007 @ 2:35 am
I use AS3 to load a SWF file,this file include some actionscript,for example:
function aaa():void{ …… }
I want use this method in _main SWF, and how can I get it?
george said
am May 23 2007 @ 9:08 am
I have an example ‘Load External Multiple Assets’ in my ‘Download’ page. In the class ‘AssetLoader’, you could find a function:
Where ‘this.content.getAsset()’ is to load a function such as ‘aaa()’ from _main SWF, you could make a reference directly to ‘this.content’ out and store it in memory such as an Array, then you can call that ‘aaa()’ whenever you want.