Denna version har förgyllts med:

How to access a swf root from Flex 3

screw pine
Creative Commons License photo credit: liangjinjian

A while ago I had to control a swf inside flex and run into trouble. As far as I could see, you either embed or load swfs symbols, which will remove all actionscripts inside your swf, or you embed/load the complete swf with everything and keep everything intact but with toruble accessing the movieclips functions and timeline.

It also seems theat Flex 2 was able to connect to the swfs root easely, but the examples I found dindt work in Flex 3.

So, I tryed to find the root of a swf when loaded with a swfLoader and came up with this:

public static function getSwfRootFromSwfLoader(swfLoader:SWFLoader):MovieClip
{
     return ((swfLoader.content as MovieClip).getChildAt(0)
         as Loader).content as MovieClip;
}

Accessing the root of the swf after that funciton worked as a charm. I used event listeners to communicate between flex and the swf just to make sure that nothing breaks in case of a problem, but thats just my choise.

Also the functions casting in the first part might not be correct but it works since thet provably inherit from the same object.

En kommentar till “How to access a swf root from Flex 3”

  1. kmf says:

    Thank you Camilo. This was most helpful!

Lämna en kommentar