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)
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.
Hi Ramsey,
I am happy you like it
Great idea, I will definitely vote and try to make it happen for future releases.
Thibault
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.
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
salut tibo,
cette ligne
[Event(name='complete', type='org.bytearray.loader.events.SWFExplorerErrorEvent')]
elle sert a quoi exactement?
a++
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
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
Thibault – Can you confirm if this requires FP10 to run?
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
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 !
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
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
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.
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() );
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!
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
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
Hi Benjamin,
Can you send me the SWF so that I can test it ?
thibault at bytearray.org
best,
Thibault
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?
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
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.
Thank you very very much. This was very useful!
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
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.
http://ironfilingz.blogspot.com/2009/11/i-found-myself-this-week-with-need-for.html
Sorry – link got truncated
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
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
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.
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.
great work and excellence stuff.
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.
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
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.
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?
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
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.
When can we see SWC version?
I find this library very helpful, thank you… I have one question: is it available for use in commercial projects?
Thanks in Advance
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
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 !
Trackbacks/Pingbacks (9)
[...] 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 [...]
[...] i have often found myself in a situation where they seemed a good idea in theory at least. So this looks [...]
[...] http://www.bytearray.org/?p=175 http://etcs.ru/pre/getDefinitionNamesSource/ [...]
[...] updated the SWFExplorer library so that you can check if any hardware acceleration has been set in the current SWF and [...]
[...] 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/ [...]
[...] 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 [...]
[...] Explorer, 佢既應用 http://www.bytearray.org/?p=175 About adminNo description. Please complete your profile. Tagged as: actionscript, code Leave a [...]
[...] http://www.bytearray.org/?p=175 Filed under: 無分類 Leave a comment Comments (0) Trackbacks (0) ( subscribe to comments on this post ) [...]
[...] all of the classes available in a SWF, perfect for SWF introspection and runtime loaded assets. SWFExplorer non longer needed! Example [...]