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.
Categories: Flex Gotchas
not working, i don’t know why. my system manager always null.
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?
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..
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();
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?
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.
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?