Tuesday, July 14, 2009

Loading a Flex SWF into a Flash SWF and Passing Parameters

What sounded like it should have been a simple task was proving to be incredibly problematic. With the same virtual engine I should have just been able to access the properties of the flex swf with a dot property/function call. But to no avail.

It was only after reading iamdeepa on Flex's post on the Flex SystemManager and understood that I was trying to access properties of the SWF when it had just loaded (ie. Still in the SystemManger loading frame). So listen for an "applicationComplete" event, before accessing your loaded swf.

[code]
private var mClip:MovieClip;

function startLoad () :void
{
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest ("Flex.swf");
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onCompleteHandler);
}

function onCompleteHandler (vLoadEvent:Event) :void
{
mClip = vLoadEvent.currentTarget.content;
mClip.addEventListener("applicationComplete", onFlexSwfLoaded);
}

function onFlexSwfLoaded (vEvent:Event) :void
{
mClip.accessInternalPublicProperty = true; // or something
}

startLoad ();
[/code]

0 Comments:

Post a Comment

<< Home