Introducing SWFExplorer 0.7 by Thibault Imbert

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().

Comments (40)

  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 #
  27. Franto wrote::

    Hey, do you know how to create swf with embedded image with SymbolClass associated to it? So I can later get it with getDefinition and instantiated? Im trying to create it with SwfAssist. I can embed image and create SymbolClass… but it’s not enough… so it seems I really have generate some class and insert it into SWF via DoABC(). Do you know how to do it? How to convert class source string into ABC?

    thank you for your help

    Thursday, August 19, 2010 at 3:17 pm #
  28. Israel wrote::

    I’m constantly amazed by the amount be the brilliant’s out there. Thank you so much for sharing this class and your brain with us.

    Sunday, October 17, 2010 at 5:03 pm #
  29. Schedule wrote::

    Best you could change the blog title Introducing SWFExplorer 0.6 – ByteArray.org to more better for your webpage you make. I liked the post however.

    Saturday, October 30, 2010 at 9:33 am #
  30. manoj sahu wrote::

    great work and excellence stuff.

    Monday, December 20, 2010 at 9:23 am #
  31. gembin wrote::

    i just using the exactly the same code as the example, but the result is not what i expected.
    i try to load framework_4.0.0.14159.swf, and i got 18 classes, something like this:
    mx.controls.RichTextEditor__embed_mxml_assets_icon_align_left_png_997153484 etc.

    Saturday, March 5, 2011 at 5:02 pm #
  32. dewey wrote::

    Hello!

    I found my way to this code, which looks to be exactly what I need, however, I want to load a local SWF. It doesn’t appear I can use the “loadBytes” method… is there a way that you know of so that I can bring in a local SWF so as to be able to “explore” it?

    Thank you,

    –d

    Monday, March 7, 2011 at 8:06 pm #
  33. Qubbe wrote::

    This has helped me out a lot.
    But I have noticed using TLF Text in the swf you wish to explore prevents the SWFExplorer from finding classes.

    Thursday, March 10, 2011 at 11:14 pm #
  34. Sris wrote::

    Thank you so much Thibault, This is exactly what I am looking for. If this works … I will be very much grateful to you.

    I tried to use the SWFExplorer …but I got the same result as Hajime mentioned in the comments section.

    Is the problem solved? If so what is the problem with his swf and how it was solved?

    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?

    Friday, April 15, 2011 at 10:43 pm #
  35. Thibault Imbert wrote::

    Hi Sris,

    Did you try with the latest version ?

    Can you send me the SWF you are using ?

    I will profile it and see what could be the issue.

    Thanks!

    Thibault

    Friday, April 15, 2011 at 11:00 pm #
  36. Felix wrote::

    Hi Thibault,

    thanks for the that library and all the others that saved me the life on one or another moment.

    I wrote this comment because im having troublesparsing a SWF that have some TLF textfields in. Seems that the definitions are broken… (ie. skin_fla.MainTimeline__Preloader__,skin_fla.MainTimeline__LoadingAnimation__)

    There aren’t symbols on the FLA with these names…

    thank you.

    Tuesday, August 30, 2011 at 6:08 pm #
  37. Konrad wrote::

    When can we see SWC version?

    Monday, September 12, 2011 at 12:07 pm #
  38. Licence question wrote::

    I find this library very helpful, thank you… I have one question: is it available for use in commercial projects?

    Thanks in Advance

    Thursday, November 17, 2011 at 6:44 pm #
  39. s9tpepper wrote::

    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 #

    It would be awesome if we could also get all the classes that are packaged in the SWF. Like someone else said, it would really unleash a lot of introspection possibilities.

    -omar

    Saturday, February 25, 2012 at 9:54 am #
  40. JAB wrote::

    Salut,

    D’abord, merci pour cette super classe, je ne compte plus les projets qui l’utilisent !

    Par contre j’ai le même problème que Qubbe et Felix : impossible d’extraire les définitions dès lors qu’il y a un champ TLF dans la bibliothèque. J’ai essayé de bidouiller un peu le code mais je n’arrive pas à les récupérer, c’est comme si elles avaient disparues !
    A la place, deux définitions apparaissent :
    “MainTimeline__LoadingAnimation__”
    “MainTimeline__Preloader__”

    Est-ce que tu aurais une solution pour ça ?

    Merci !

    Wednesday, May 16, 2012 at 1:23 pm #

Trackbacks/Pingbacks (9)

  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 ) [...]

     
  9. [...] all of the classes available in a SWF, perfect for SWF introspection and runtime loaded assets. SWFExplorer non longer needed! Example [...]