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 06/11/09 : Released SWFExplorer 0.6 (fixed a bug related to SWF dimensions).

Comments (26)

  1. Ramsey wrote::

    Very helpful library. Thanks.

    I decided to re-open the feature request for “getDefinitions” http://bugs.adobe.com/jira/browse/FP-564

    Hopefully it can make it in the new version with a few votes behind it.

    Tuesday, August 19, 2008 at 10:30 pm #
  2. Thibault Imbert wrote::

    Hi Ramsey,

    I am happy you like it :)

    Great idea, I will definitely vote and try to make it happen for future releases.

    Thibault

    Tuesday, August 19, 2008 at 10:46 pm #
  3. austin wrote::

    You are so awesome, this library absolutely kicks ass. This is so useful and I can see a lot of future ideas with this lib.

    Tuesday, August 19, 2008 at 11:24 pm #
  4. Marty Pitt wrote::

    This is awesome, Thibault.

    The ability to get a list of classes within a project makes reflection so much more powerful! Thanks so much.

    Marty

    Wednesday, August 20, 2008 at 1:01 am #
  5. gropapa wrote::

    salut tibo,
    cette ligne
    [Event(name='complete', type='org.bytearray.loader.events.SWFExplorerErrorEvent')]

    elle sert a quoi exactement?
    a++

    Wednesday, August 20, 2008 at 10:51 am #
  6. Thibault Imbert wrote::

    Salut gropapa,

    C’est juste pour que Eclipse affiche directement lors de l’écriture de la méthode addEventListener les événements diffusés par l’objet.

    Ca permet de faire gagner du temps au développeur qui voit directement les événements diffusés.

    Je t’ai fait une petite capture disponible ici :

    http://www.bytearray.org/wp-content/projects/swfexplorer/event-parsing.png

    ++

    Thibault

    Wednesday, August 20, 2008 at 11:14 am #
  7. Thibault Imbert wrote::

    Hi guys,

    I am very happy you like it. There are many use cases with this lib. I will add some more stuff to it if you need something special let me know.

    Thibault

    Wednesday, August 20, 2008 at 3:08 pm #
  8. Marty Pitt wrote::

    Thibault – Can you confirm if this requires FP10 to run?

    Wednesday, August 20, 2008 at 5:39 pm #
  9. Thibault Imbert wrote::

    Hi Marty,

    This library does not require the Player 10. You can use it with the Player 9, I used the Player 10 to use the new FileReference capabilities to load a local stream in the app :)

    best,

    Thibault

    Wednesday, August 20, 2008 at 5:46 pm #
  10. Julien Revel wrote::

    Hi
    I tried to analyze the bytes of an application, through “this.root.loaderInfo.bytes” inside the Application class

    Unfortunately, I only see those classes that are generated through embedded assets.
    I do not see any of my custom classes… too bad !
    Do you have an idea of how to list all classes of an already loaded application ?

    Thanks for this great development anyhow, you have to master SWF files !

    Wednesday, August 20, 2008 at 8:29 pm #
  11. Thibault Imbert wrote::

    Hi Julien,

    The library for now is extracting all the classes attached to symbols in the SWF library. If I understand right, what you would like to do is extract also the custom classes available in the SWF ?

    best,

    Thibault

    Wednesday, August 20, 2008 at 9:29 pm #
  12. Julien Revel wrote::

    Yes Thibault, you understood me right. It would be great to be able to discover all custom classes in any SWF, so that we could unleash introspection power.

    Thanks
    julien

    Thursday, August 21, 2008 at 11:53 am #
  13. Rezmason wrote::

    Darn it darn it! I just made a class like this! Granted, it only finds definitions for objects in the display list, but I was proud.

    I guess I’ll just have to use your class. Nice. REAL NICE. :D

    Friday, August 22, 2008 at 3:20 am #
  14. Rezmason wrote::

    Request- why are the class definitions returned in an Array? It’d be much cooler, I think, if you’d return an Object like so:

    // output: [object MyClass]
    trace( new SWFExplorer.library.MyClass() );

    Friday, August 22, 2008 at 3:46 am #
  15. CaioToOn! wrote::

    Hi, Thibault.

    It’s kind of off topico, but, excuse me if it is a beginner question, but when you retrieve the FrameRate and FrameCount (lines 113 to 115) you use readByte() and readShort() respectively, shouldn’t it be inverted, since the frame rate is a 32-bit?

    Cheers,
    CaioToOn!

    Monday, August 25, 2008 at 8:40 pm #
  16. Thibault Imbert wrote::

    Hi CaioToOn!

    This is an interesting question. In fact the frame rate is supposed to be stored as a 16-bit integer. So 2 bytes are reserved for the frame rate. Actually, the first byte is ignored. That’s the reason why in the Flash IDE the maxiumum frame rate you can set it to 120 maxiumum, which fits in 1 byte.

    If the SWF is compiled with the Flex compiler and the frame rate is set to something higher than 255 (full byte) then the other byte should be considered and I should read the frame rate with readShort().

    I will take that in account and read it this way.

    Thanks :)

    Thibault

    Monday, August 25, 2008 at 9:27 pm #
  17. Benjamin wrote::

    Hi Thibault,

    Thanks for sharing this code with us! I’m excited to implement this functionality, but I can’t seem to get it to recognize my exported library assets.

    I have a Flash app that needs to load in some external font libraries, which are .swf files with fonts embedded in the library, and exported for actionscript (with the “export in first frame” option checked by default). I must be doing something wrong, because I can see that the symbolClasses array has a length of zero after it’s been filtered.

    Well, I wish I knew enough about this to troubleshoot, but any help is greatly appreciated.

    Cheers,
    Benjamin

    Thursday, August 28, 2008 at 8:24 pm #
  18. Thibault Imbert wrote::

    Hi Benjamin,

    Can you send me the SWF so that I can test it ?

    thibault at bytearray.org

    best,

    Thibault

    Thursday, August 28, 2008 at 8:57 pm #
  19. hajime wrote::

    Hi Thibault,

    I was looking for exactly what you did here. But I can’t seem to get the explorer to see my classes in the external .swf

    Basically what I did was create an as3 project in flash cs3, then created a bunch of shapes and imported some images.

    Then for each of these movieclips ( i converted all of them to separate movieclips ), in their properties under the linkage section, I typed in a class name for them e.g. ‘item_1′, ‘item_2′, etc, and the options ‘export for actions script’ and ‘export in first frame’ are both selected.

    Using the above exmaple code given, i directed the explorer to load the .swf, but i get a 0 from the trace.

    Did i do something wrong in my swf?

    Monday, March 2, 2009 at 8:13 am #
  20. Thibault Imbert wrote::

    Hi hajme,

    I am interested to see your SWF. Can you send me by email thibault {at} bytearray.org your FLA so that I can take a look ?

    best,

    Thibault

    Monday, March 2, 2009 at 7:44 pm #
  21. Sreenivas wrote::

    code given above is not working (SWFExplorer which lets you browse an SWF and extract all the exported classes definitions available in an SWF.
    ).can any one please send the complete code which will retrieve the images from the .swf file and store in to the array.

    Thursday, May 28, 2009 at 5:31 pm #
  22. Ian James wrote::

    Thank you very very much. This was very useful!

    Sunday, September 27, 2009 at 6:42 am #
  23. wm wrote::

    looks really useful Thibault, gets the contents of a swf just fine. I can’t seeem to instantiate an instance of any of the classes tho. normally using a loader I would expect to have to do something like
    var context:LoaderContext = new LoaderContext(); context.applicationDomain = ApplicationDomain.currentDomain;
    so I can use getDefinitionByName. Obviously I’m missing something as I can’t do that with swfexplorer. How does ApplicationDomains work with reagrd to swfexplorer

    Tuesday, November 24, 2009 at 3:38 pm #
  24. wm wrote::

    link to my solution to the previous query. If there is an obvious problem with using SWFExplorer this way perhaps you could let me know. Thanks a lot.

    Tuesday, November 24, 2009 at 7:15 pm #
  25. wm wrote::

    http://ironfilingz.blogspot.com/2009/11/i-found-myself-this-week-with-need-for.html

    Sorry – link got truncated

    Tuesday, November 24, 2009 at 7:17 pm #
  26. Thibault Imbert wrote::

    Hi wm,

    Yes! Nice use and modification done to the SWFExplorer class. What I usually do is using the SWFExplorer class which loads the SWF then I retrieve the definitions then inject the SWF in a Loader through the loadBytes method.

    I have then, all the definitions and a Loader with its ApplicationDomain where I can retrieve the definitions.

    Thibault

    Wednesday, November 25, 2009 at 12:45 am #

Trackbacks/Pingbacks (8)

  1. onebyoneblog » enabled v. mouseEnabled & Other Stuff on Thursday, August 21, 2008 at 1:14 am

    [...] haven’t tried this out yet, but if it’s from Thibault Imbert, it has to be good. It’s a handy utility class that will rummage through a loaded .swf file and [...]

     
  2. [...] i have often found myself in a situation where they seemed a good idea in theory at least. So this looks [...]

     
  3. [...] http://www.bytearray.org/?p=175 http://etcs.ru/pre/getDefinitionNamesSource/ [...]

     
  4. [...] updated the SWFExplorer library so that you can check if any hardware acceleration has been set in the current SWF and [...]

     
  5. [...] on peut utiliser des classes qui introspectent la totalité des classes disponibles dans le SWF http://www.bytearray.org/?p=175 (uniquement pour les symboles DisplayObject) ou http://etcs.ru/pre/getDefinitionNamesSource/ [...]

     
  6. [...] out the different options – RSL, Module, straight up loading a SWF. Just found a post by Thibault Imbert (bytearray.org) that is making me think I’ll go with loading a SWF, but still thinking it [...]

     
  7. [...] Explorer, 佢既應用 http://www.bytearray.org/?p=175 About adminNo description. Please complete your profile. Tagged as: actionscript, code Leave a [...]

     
  8. SWFExplorer « CODE@蝴蝶。夢 on Wednesday, July 21, 2010 at 10:35 am

    [...] http://www.bytearray.org/?p=175 Filed under: 無分類 Leave a comment Comments (0) Trackbacks (0) ( subscribe to comments on this post ) [...]