Search code examples
apache-flexflashactionscript-3flex4swfloader

external swf control flex application?


I have a flex application that loads an external swf file. I created the external swf file using flash cs4 so I can add code to it if that is what it takes.

Here is the code I use to load my external swf:

//add button swf
var request:URLRequest = new URLRequest("http://www.yadayada.com/media/but_button.swf");
var loader3:Loader = new Loader();
loader3.load(request);
addChild(loader3);
//position the ZoomControls

loader3.y = 0;
loader3.x = 0;

Can I have my external swf send click events to my flex application? How?


Solution

  • yes, you can do it.

    function loadExternal():void {
      loader3.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
      loader3.load(request);
      addChild(loader3);
    }

    function onComplete(e:Event):void { var mc:MovieClip = MovieClip(e.target.content); mc.addEventListener(SomeEvent.EVENT_TYPE, onSomeEvent); mc.someExternalFunction(); //external function too can be called }

    You need to make External SWF in a way so that it allows cross scripting. So you need to put Security.allowDomain("*"); // will make it's functions available to any swf loaded from any domain inside external swf.