Home > Flex Gotchas > Casting swfLoader.content as SystemManager

Casting swfLoader.content as SystemManager

So I was trying to load an application into another and was using SwfLoader.

When I received the INIT (or COMPLETE) events from the loader, I was trying to cast the .content property as SystemManager (since that’s what it is) but the type cast was failing.

The solution is to set the SwfLoaders loader context property with a new context and pass in the current application domain.

var loader:SwfLoader = new SWFLoader();

loader.loaderContext = new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDoman));

Now you can cast the content property as a SystemManager.

Yippie.

Advertisements
Categories: Flex Gotchas
  1. stanley
    February 18, 2010 at 8:45 PM

    not working, i don’t know why. my system manager always null.

  2. roustalski
    February 18, 2010 at 9:03 PM

    In debug, when you look at the content property in debug, do you see it typed as a system manager, but when you cast it, it is null, or is the content property always null?

  3. stanley
    February 18, 2010 at 9:48 PM

    the content is not null, i can see it like [Object variable]
    the swf file is compiled from flash.
    but everytime i try to cast it to System Manager, the systemManager object is always null. and thats why it fails to run the next line : systemManager.addeventlistener..

  4. stanley
    February 18, 2010 at 11:22 PM

    sorry for the troubles.
    solved it.
    if the swf is not a flex application (i.e. a normal flash file)
    don’t need to use SystemManager at all.
    just do:
    var swfObject:Object = swfLoader.content as Object;
    swfObject.methodname();

  5. Metin
    March 31, 2011 at 1:50 AM

    ok where is the methodname in flash? can we access to property of flash ( like button, …). I wanna use button from flash and i wanna do clickable button from flex 4, adding mouse click event from flex, is it possible?

    • March 31, 2011 at 7:04 AM

      Yes, you load in your swf, access the button with the ID property that is used in the swf, and then add an event listener as you would in flash.

  6. Metin
    April 1, 2011 at 3:46 AM

    do we have to load swfs using movieClip class?
    that code is working in flex 4

    in the method at the below code:

    var loadedMc:MovieClip = MovieClip(myLoader1.content);
    loadedMc= MovieClip(myLoader1.content);
    //access the button with instance name myButton: loadedMc.server2.addEventListener(MouseEvent.CLICK, onBtnClick2);
    //onBtnClick2 mouse event function that must be handle in code
    //server2 the property in the swf

    is it the right way to access to property of swf? is there any way to load dynamically?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: