Example of casting contents of swfLoader to an interface

english mobile

Last weekend, someone asked for ane example of being able to load a swf generated from a Flex Application that implements an interface and being able to load a Flash swf that implements the same interface. Once the swf's are loaded, the poster wanted to be able to cast them to the interface and then use the interface to call methods on the loaded swf.

So, I've posted an example of casting swfLoader content to an interface.



I chose to go pretty generic with this example, so the interface just enables you to make the component "blush" and stop blushing. However, this could have a lot of uses, for instance, you could write an interface that allows you to stop all animation within a swf.

5 comments:

Omar Cisneros said...

Please, can you share the code for how to do this?

Is just what i need.

Thanks

Unknown said...

Omar, when you are viewing the Flex application, just right-click on it and from the context menu select 'View Source'.

Omar Cisneros said...

TY, i moments before posting the question i realized it. Anyway, TY.

pgrier said...

Thank you Amy. Using some of the techniques you have here, I am hoping to integrate an animated flash character into a flex application and trigger various movements from the flex app. I don't know flash yet so i was wondering if all of the runtime methods have to be predefined on the flash side for use in the interface or if it is just as easy to manipulate each flash object from flex.

Thanks again

Amy B said...

The point is that by implementing an Interface on the Flash side, the Flex side doesn't need to know anything about what is going on inside the Flash movie. So you can easily switch it out for a different Flash movie or other object that implements the same Interface.

If you don't feel that you need to plan for that scenario, then you can just cast the swf to the Base class type or your custom class associated with the swf.