E-Madd
E-Madd

Reputation: 4572

Flex: How to call function of embedded swf?

I have a Flex 3.4 app that embeds a swf with mx:SwfLoader...

That swf has a public function named "playIt". I've tried dispatching events to gettingHere.content, casting gettingHere.content as a MovieClip and other stuff...

var swfApp:MovieClip = MovieClip(gettingHere.content); if (swfApp.hasOwnProperty("playIt")) { var helloWorld:Function = (swfApp["playIt"] as Function); helloWorld(); }

to no avail. Help!

Upvotes: 1

Views: 2880

Answers (2)

Pythovore
Pythovore

Reputation: 77

Are you able to load the swf into Flex at runtime rather than embed it? I've had good results loading swfs into Flex after launch, whereas embedding tends to be problematic for accessing a swf API.

Either use Loaders with eventListeners in a script or mx:SWFLoader in MXML with a listener on complete should work for you.

Upvotes: 0

Michael Brewer-Davis
Michael Brewer-Davis

Reputation: 14276

See the example here for interacting with a loaded Flex application.

Essentially:

var swfLoader:SWFLoader; // assuming loading complete
var loadedSM:SystemManager = SystemManager(swfLoader.content);
var loadedApp:Object = loadedSM.application;

app.playIt();

Upvotes: 2

Related Questions