Skip to main content
Known Participant
June 5, 2009
Question

Enumerate exported classes/symbols

  • June 5, 2009
  • 3 replies
  • 1250 views

Hi all,

When I load an swf dynamically using the Loader, is there any way that I can retrieve the symbols that are exported as as3 classes?

I know I can instantiate the symbols when I know the classname using

loaderInfo.applicationDomain.getDefinition(fullyQualifiedName) as Class

But I can't find something like

applicationDomain.getDefinitions() which would result an array of fully qualified classnames, like

["com.company.app.Symbol1", com.company.app.Symbol2",..]

so I can instantiate symbol1 and add it to the stage like

var cls:Class = loaderInfo.applicationDomain.getDefinition("com.company.app.Symbol1") as Class

var obj:*;

try {

     obj=new cls;

} catch (error:Error) {

     trace('Cannot instantiate the class');

}

stage.addChild(obj);

If this is impossible, please let me know too. In that case I have to fill my database with all the symbols per swf and load that too.

But it's a lot more work creating and maintaining duplicate data.

I know there are tools out there that can show everything that's contained in an swf, but I don't know if they're looking at the binary data.

TIA

Ronald

This topic has been closed for replies.

3 replies

June 5, 2009

Oh... and yes, you need to look at the binary data. But you can easily have the swf load itself.

ron71nlAuthor
Known Participant
June 5, 2009

What do you mean by have the swf load itself?

June 5, 2009

Well, if you needed to enumerate the class definitions in a main swf (not one that's loaded using a Loader), you could use a URLLoader to "reload" the swf.

i.e.

     var urlLoader:URLLoader = new URLLoader();

     var ldrInfo:LoaderInfo = this.loaderInfo;

     urlLoader.dataFormat = URLLoaderDataFormat.BINARY;

     urlLoader.load(new URLRequest(ldrInfo.url));

... and then run it through SwfClassExplorer

ron71nlAuthor
Known Participant
June 5, 2009

Oh wel, I solved it myself FYI:

I can't figure out how to enumerate all exported classes, but if you add all exported classes to the stage of the swf you want to load dynamically,

you can enumerate the children of the loaded MovieClip.

var loader:Loader = new Loader();

var loaderInfo:LoaderInfo = loader.contentLoaderInfo;

loaderInfo.addEventListener(Event.INIT, onInit);

...

... Add the URLRequest etc

...

loader.load();



public function onInit(e:Event):void {

    // e.target.content is the stage of the loaded SWF, as a MovieClip object

    var movieClip = e.target.content as MovieClip;


    if(movieClip.numChildren>0) {

        for(var i:int = 0; i< movieClip.numChildren; i++) {

            var child:Object = c.getChildAt(i);

            trace(child.name);                                     // The instance name of the symbol on the swf's stage

            trace(getQualifiedClassName(child));      // The fully qualified classname of the symbol (import flash.utils.*)

        }

    }

}             

Best regards,

Ronald

kglad
Community Expert
Community Expert
June 5, 2009

rb gave a link to a more elegant and efficient (and therefore easier for you) way to do this.

ron71nlAuthor
Known Participant
June 5, 2009

Thanks!

One last question though, If I were to use an swf compressor to save bandwidth, would that have any impact on the SwfClassExplorer?

I suppose not, as the compressor will in the end provide the same uncompressed binary code, which can be interpreted using the classExplorer, isn't it?

Ronaldo

June 5, 2009
ron71nlAuthor
Known Participant
June 5, 2009

Hmmm. I wish I had found this earlier. Thanks for the tip!

The only downside I see is that when the Adobe changes the bytecode, it might not work any more.

But can we expect changes in the bytecode? I don't think so.

I'll definitely have a close look at it.

Ronald

June 5, 2009

I don't see changes coming anytime soon to the swf file format. But even if there were a change, you could easily check the version in the header, and adjust the parsing accordingly.