开发者

Loader.loadBytes and getDefinitionByName

开发者 https://www.devze.com 2022-12-19 14:44 出处:网络
I am currently working on a project that will load a swc, inspect it and allow the user to view the classes inside.

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 solut开发者_JAVA百科ion:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号