tags:

views:

290

answers:

1

Hi All

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?

Thanks

+4  A: 

Loader.loadBytes does fire a complete event. Remember to add your listener to Loader.contentLoaderInfo.

However, if you are loading a SWF file which was part of a SWC file compile with a FlexSDK prior to version 4 you will not get the Event.INIT method since it is only fired when a document class is availalable. Such a class is injected by the compiler since SDK version 4.

Joa Ebert
Many Thanks for the speedy and accurate answer. I've been caught out with that before. It seems odd that they do it this way. If they returned an info object for each load call then I could see that it was for concurrent load. The way it's implemented at the moment if there were concurrent loads you wouldn't be able to listen for different events.
Roaders