-
http://alecmce.com/as3/interfacing-swf-files Interfacing SWF Files at AlecMcE.com
-
http://www.visible-form.com/blog Rich Rodecker
-
http://www.visible-form.com/blog Rich Rodecker
-
Anonymous
-
vizio
-
http://blog.vizio360.co.uk/2009/12/unload-issue-with-external-swf-files-that-implement-an-interface/ vizio 360º » Unload issue with external SWF files that implement an interface
-
Anonymous

Using SWF files that implement a Specific Interface
How about modularizing your application so that other developers can develop external modules by only knowing a specific set of interfaces. Based on this idea I built a little test to see if it’s possible to create SWF files which main class implements a specific Interface, then loading them into another SWF and cast them to the Interface specified, and I found out that it works!
here is the test:
First of all I’ve created my Interface:
MyInterface.as
package { public interface MyInterface { function getValue():String; function setValue(value:String):void; function getRandomInt():int; } }I’ve created a swf file that implements the interface above
SWFImplementingMyInterface.as
package { import flash.display.Sprite; public class SWFImplementingMyInterface extends Sprite implements MyInterface { private var myValue:String; public function MyExternalClass() { } public function getValue():String { return myValue; } public function setValue(value:String):void { myValue = value; } public function getRandomInt():int { return 125; } } }And finally another SWF that loads the previous SWF, casts it to MyInterface and use MyInterface’s methods.
package { import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; public class Main extends Sprite { private var loader:Loader; private var myVar:MyInterface; public function Main() { loader = new Loader(); addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } private function onAddedToStage(event:Event):void { loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onExternalSWFLoaded); loader.load(new URLRequest("MyExternalClass.swf")); } private function onExternalSWFLoaded(event:Event):void { try{ myVar = MyInterface(loader.content); trace("random int = "+myVar.getRandomInt()); myVar.setValue("a value"); trace("value = "+myVar.getValue()); }catch(castingError:TypeError) { trace("Error : "+castingError.message); } } } }It sounds like something obvious but with Adobe sometimes you cannot assume that everything works as expected
download all the files above.