Open Flash CS4, create new AS3 FLA, add as3swf.swc and paste this on frame 1:

import com.codeazur.as3swf.SWF;
var swf:SWF = new SWF(root.loaderInfo.bytes);

Trace output:

    Version: 10
    FileLength: 149405
    FileLengthCompressed: 149405
    FrameSize: (550,400)
    FrameRate: 24
    FrameCount: 1
    [69:FileAttributes] AS3: true, HasMetadata: false, 
      UseDirectBlit: false, UseGPU: false, UseNetwork: false
    [09:SetBackgroundColor] Color: #FFFFFF
        [0] Frame: 0, Name: Scene 1
    [82:DoABC] Lazy: true, Length: 149219
        [0] TagID: 0, Name: Untitled_fla.MainTimeline

Excercise: Draw something on stage, and run the code again.

Want more? Drop by my session Hacking SWF at FITC Amsterdam (Feb 22th, 16:00).

[Edit] Jim Cheng deserves credits. He was the one who whispered “root.loaderInfo.bytes” into my virtual ear on IM.

19 thoughts on “SWFtrospection

  1. I did not know you can get to the ABC of the current SWF. Wow! This is fantastic Claus. Looking forward to your talk at FITC!

  2. Hi Claus, Amazing work. I would love to attend your talk at FITC, but I wont be there :( (too faraway for me). I’m starting a new project called xml2swf made with Actionscript. I’m checking out your as3SWF, I think it will be usefull for my project. I invite you to check out my project at http://github.com/rayaslokas/xml2swf maybe you can find some usefull classes. Best Regards :)

  3. Looks like this is a nice way to solve the offstage content bug when loading a swf – seems that where a swf with offstage content would return the content dimensions rather than its stage dimensions, by accessing FrameSize, we can get the actual stage dimensions. Nice.

  4. @Pedr

    You should be able to get to this info through the content’s LoaderInfo.width /.height properties without needing a util class (not that I am devaluing Claus’ excellent work in any way)

  5. This is great work. I’ve been trying to figure out a way to get a vector SWF exported from Livebrush (with all the vector decorations). No luck so far. Wish I could attend.

  6. Miguel: I too was thinking about creating some proprietary XML format to export to and import from (similar to what swfmill does). Care to contribute?

    David: as3swf does not roundtrip yet, especially shape publishing is missing yet. Pure lazyness on my part, i might add.. it’s perfectly doable. Right now (until FITC) my focus is on shape-etc export though.

  7. Miguel: btw there is also XFL (or is it FLX? The new XML based FLA format) you could export to. I don’t think there are specs out there yet, though

  8. Claus: My library is very similar to swfmill. I was using swfmill, but it don’t work fine for the linkage names for as3, for this reason I wrote my own solution. My xml2swf for the moment only allow you to create a swf with only one MC into. I must improve that to support many MC into. I would love to contribute you (in the way I can). I will continue with my lib too. :)…. About XFL. I didn’t know it, I was reading and looks like will make the same work, then maybe my lib have not sense. jejeje, but well.. it is the life. My lib is more nostalgic, it is made with as3 :)

  9. Great post, I like your project so much.
    codeazur as3swf is a very complete framework!

    Howerver if you want to get the bytecode out of a swf, you dont need any framework!

    Check this out: http://jpauclair.net
    It’s a set of hidden feature of flash, and one of theses enable you to print the SWF bytecode directly in your flashLog.


  10. Pingback: FITC Amsterdam 2010: iPhone Topics » GELB der Powerflasher Blog

  11. Hello Claus,

    Really good work, very very useful !

    Could you publish an example of how to use as3swf to create / publish swf files ?

    good continuation !

  12. I really loved w3blog » Blog Archive » SWFtrospection – Claus Wahlers on Application Development, Web Standards and what not.. This is achieved not by beginners luck, but by what is called Search engine optimization, or SEO for quick.

  13. Wow, Thank you because of this blog. Thats all I’m able to say. You almost certainly have made this blog into some thing thats eyesight opening and important. You obviously know much about the topic, youve covered a lot of bases. Great stuff from this area of the internet. Again, thank you for this blog.

Comments are closed.