I am currently working on a project that will load a swc, inspect it and allow the user to view the classes inside.
I load the library.swf using Loader.loadBytes (the bytes come from the unzip library I use). I create an instance of the class using getDefinitionByName.
This all works fine as long as getDefinitionByName is called on the next frame. If I call it straight away I get a reference error. To get round this I've come up with a rather hacky solution:
private function processLibraries( event : Event ) : void
_zipFiles.forEach( processSwfs );
DisplayObject( FlexGlobals.topLevelApplication ).addEventListener( Event.ENTER_FRAME, enterFrame );
private function enterFrame( event : Event ) : void
DisplayObject( FlexGlobals.topLevelApplication ).removeEventListener( Event.ENTER_FRAME, enterFrame );
_classCollection = new ArrayCollection();
_zipFiles.forEach( processCatalogs );
complete( _classCollection );
I really don't like using the enter frame event on the top level application. I also don't want to have to set up a timer. That's just as nasty.
Loader.loadBytes doesn't fire a complete event so I don't know where I listen for an event for when the bytes have been fully loaded into the ApplicationDomain.
There must be a neater way round this?
Loader.loadBytes() does fire a complete event. Try something like this: