In a recent project I had to use runtime shared libraries. In ActionScript 3, the use of external libraries is made easy through the ApplicationDomain class and the getDefinition method. But one common limitation of the getDefinition method is that you have to know the name of the class definition you want to extract.

A cool addition would be a getDefinitions method which would return an Array of definitions. :) Unfortunately such a feature is still missing in Flash Player 10.

Vote for a getDefinitions() method on ApplicationDomain.

That's the reason why is created this tiny library called SWFExplorer which lets you browse an SWF and extract all the exported classes definitions available in an SWF.

Here is a tiny piece of code to illustrate how it works :

var explorer:SWFExplorer = new SWFExplorer();

explorer.load ( new URLRequest ( "library.swf" ));

explorer.addEventListener ( SWFExplorerEvent.COMPLETE, assetsReady );

function assetsReady (e:SWFExplorerEvent):void
{

// outputs : org.groove.Funk,org.funk.Soul,org.groove.Jazz
trace( e.definitions );

// outputs : org.groove.Funk,org.funk.Soul,org.groove.Jazz
trace( e.target.getDefinitions() );

// ouputs : 3
trace( e.target.getTotalDefinitions() );

}

The getDefinitions method returns an array of class names that you can use to call the getDefinition method.

The code above can be used for a remote library, if you want to parse some SWF bytes you may have already loaded, the SWFExplorer class contains a simple parse() method which returns the definitions :

var definitions:Array = explorer.parse(libraryBytes);

// outputs : org.groove.Funk,org.funk.Soul,org.groove.Jazz
trace( definitions );

// outputs : org.groove.Funk,org.funk.Soul,org.groove.Jazz
trace( explorer.getDefinitions() );

I hope this library will help you guys working with runtime shared libraries.

This is a first beta version that I will extend, SWC support will be added and more to come.

You can download the library here.

Note : This library does not require Flash Player 10 to run. You can use it with Flash Player 9.

Update 08/22/08 : Denis Kolyako posted a few days ago another class which also extracts also the non linked classes. Very nice!
Update 01/31/11 : Released SWFExplorer 0.7 (refactoring).
Update 03/30/12 : Flash Player 11.3 and AIR 3.3 now integrates natively getQualifiedDefinitionNames().