The Secret Life of SWFs: Flex 2’s undocumented SwfxPrinter tool
April 8, 2007 on 12:35 am | In Flex, Programming, Uncategorized | 15 CommentsIt’s apparently a well-kept secret, but the Flex SDK includes a very useful tool for examining the structure and contents of SWF files. The Java class flash.swf.tools.SwfxPrinter, which lives in the Flex 2 SDK’s lib/swfkit.jar library, is an undocumented utility that dumps AS3 SWF files as XML documents. These dumps can provide really useful insight into what is taking up space in a compiled AS3 Flash or Flex application.
If you’re in the FLEX_HOME/lib directory you can run it as follows:
java -classpath asc.jar;swfkit.jar flash.swf.tools.SwfxPrinter [options] swfFilename
Here’s a somewhat random excerpt from some output; this includes some Flash sprite definitions:
<DefineSprite id='28'>
<!-- sprite framecount=1 -->
<PlaceObject2 idref='27' depth='2' matrix='t0,0'/>
<ShowFrame/>
</DefineSprite>
<ScalingGrid idref='28' grid='(80,80),(1200,360)'/>
The valuable -showoffset option causes the output to include the offset and size of each element in the file. For instance, the following DefineFont3 element shows the size of an embedded font from a Flex CSS stylesheet:
<!-- offset=86441 size=35356 --> <DefineFont3 id='112' font='Myriad' numGlyphs='232' italic='false' bold='false' ansi='false' wideOffsets='false' wideCodes='true' shiftJIS='false' langCode='0' hasLayout='true' ascent='17019' descent='5120' leading='614' kerningCount='0' codepointCount='232' advanceCount='232' boundsCount='232'>
Sadly, in a regular application SWF, there is no information about how the code is broken up; all you get is a single element representing the entire code of the application in a single lump:
<!-- offset=291066 size=1338571 --> <DoABC2 name='frame2'> </DoABC2>
Not to worry. Far more useful are the results of using SwfxPrinter on the SWF that’s inside a SWC (just use any ZIP decompression tool to unpack library.swf from a SWC file). Now you’ll see information like this:
<!-- offset=2130104 size=4192 --> <DoABC2 name='mx/effects/CompositeEffect'> </DoABC2> <!-- offset=2134296 size=670 --> <DoABC2 name='mx/effects/Parallel'> </DoABC2> <!-- offset=2134966 size=4111 --> <DoABC2 name='com/allurent/containers/AnimatedViewStack'> </DoABC2>
Now that’s more like it!
So… I’m in the process of writing an Apollo-based tool that analyzes SwfxPrinter dumps, along with the linkage dependency information found in a SWCs, and allows developers to analyze both code size, linkage dependencies and associated source code/documentation in a single environment. Granted, it would probably make more ultimate sense to do this as an Eclipse plugin alongside Flex Builder, but which would you rather do to read in swfx dumps: deal with the Java XML APIs or hack some E4X? Also a lot of the analyzed information is easy to display in HTML, and Apollo has that nice built-in web browser.
Here’s a screen shot of some work in progress:

One can use a tool like this to find out exactly how much space each individual class or package in the application takes up, and use that to tune its space requirements, Module loading strategy, and so on — this takes a lot of work, of course, but it’s a lot easier with the right information at one’s fingertips.
I’m thinking about the dependency-analysis angle. My current thought is to support two complementary approaches: 1) discover what other classes a given class/package depends on (and thus drags into the SWF), and 2) discover which dependencies caused the inclusion of a given class/package in the SWF. The first approach is useful when one has a good heuristic notion about what should be separated out (like a complex but rarely displayed view). The second is useful when you can see a large bunch of code and you’d like to understand what other stuff is using it, so you can separate out that stuff and avoid dragging the expensive code into the SWF up front. Either way, you identify candidate classes for modification, removal, or placement in a loadable module, in the name of a smaller download size.
Note: A somewhat more convenient way to run SwfxPrinter is to just copy this swfxprinter.jar file into FLEX_HOME/lib; then you can run it in any directory as follows:
java -jar %FLEX_HOME%/lib/swfxprinter.jar [options] swfFilename
(I’m not redistributing any Adobe code here of course; the JAR file just contains a manifest with references to class and library names.)
Abrupt YouTube security policy change
December 14, 2006 on 9:15 pm | In Flex, Programming, Uncategorized | 2 CommentsThere was a brief glitch in ReviewTube operation this last week, as the fallout from an unexpected YouTube security policy change.
Some links:
Possibly due to an exploit, they abruptly changed their crossdomain.xml file to only allow access from the youtube.com domain. As a result, YouTube developer API calls from Flash no longer work if the SWF was downloaded from a non-youtube.com domain. This broke a few aspects of ReviewTube that used that API.
I quickly got around the problem by proxying the YouTube requests through my own web server. Recall that ReviewTube was created to demonstrate an architecture for remote Flex applications. Well, in a validation of that architecture, it took changes to about 3 lines in 3 source files to make this change. Two changes were to code in the Service layer, and one change was to the component configuration file. (Full disclosure: also about 10 new lines of Rails code on the server side to do the proxying.)
So… we’re back live.
YouTube, if you want to be safe and not screw up Flash/Flex developers, please move your API to a different domain and put a liberal crossdomain.xml on that host. Thanks.
Day 2: Lizard Head Pass to Bolam Pass
July 11, 2006 on 12:29 pm | In Bicycling, Uncategorized | No CommentsThis morning it was crystal-clear, with no hint of the previous day’s nasty weather. We could clearly see the dramatic surroundings of our campground: the 14,000+ peaks of El Diente and Mt. Wilson stared across the valley, with the eccentric volcanic plug of Lizard Head itself rising nearby. (Lizard Head, by the way, was considered the hardest climb in Colorado for much of the first part of the 20th century, because it’s made out of crumbly, unreliable garbage rock. Climbing guides of the period advised taking a photo of Lizard Head and turning around to head home. The lizard-head-looking part apparently decayed and fell off some time ago, leaving everyone to wonder what was the idea behind the name.) [Continued...]
Day 1: From Telluride to “A Night At The Y”
July 10, 2006 on 11:06 pm | In Bicycling, Uncategorized | No Comments(Note: photos of the entire trip can be viewed here.)
This morning broke with a crystal-clear blue sky: my prayers for good weather had been finally answered, or so I thought. I dropped off the rental car in Durango and rode to the rendezvous in back of Mountain Bike Specialists on Main Street to meet the Western Spirit truck, the guides, and the other folks with whom I’d be riding the next 5 days. Our guides were Rachel, Scott and Jason; Rachel and Scott were a married couple looking to be in their 40s and were veteran guides for Western Spirit, while Jason was in his 20s and guiding the route for the first time. [Continued...]
An Arboreal Addendum, or, More About Flex Trees
June 23, 2006 on 8:56 pm | In Uncategorized | 1 CommentYesterday I discovered one more detail that can potentially fry one’s ITreeDataDescriptor implementation: in the public release of Flex 2, the ICollectionView instance returned from ITreeDataDescriptor.getChildren() will have to implement the [] operator, with integer arguments. In other words, it has to be indexable like an Array. This is not part of the ICollectionView contract; it’s an extra, undocumented requirement imposed by the Tree code. If you use ArrayCollection or ListCollectionView as your concrete type, you’ll be OK, since they do support indexing via []; likewise, FDS collections are probably also OK (though I haven’t tested this).
If you are rolling your own ICollectionView implementations like we are, this means you’d better extend flash.util.Proxy so you can implement []. Fortunately we already had, for other reasons.
Furthermore, data paging is not respected for these child node collection views. Whatever you return from getChildren() will be scanned in its entirety, and any ItemPendingErrors thrown during the process will be ignored. So you’d better not return some huge collection there that you hope will be paged in gradually as the user scrolls through the expanded node’s children. Ain’t gonna happen that way. This probably does affect FDS remote collections, so if you return one of those from getChildren() it might not page in the way you’d hope for.
Suggestive patterns in my tea leaves have led me to retain hope that this will be fixed in some reasonable timeframe. I’m working around the problem for now.
Holyoke-Skinner State Park
May 29, 2006 on 12:48 pm | In Uncategorized | No CommentsI rode yesterday at the Holyoke-Skinner State Park Topeak-Kenda MTB Adventure, and had the greatest time. The trail system there is exceptional in its variety, pacing, technical challenge, and natural beauty.
Max and I drove out to very early to get breakfast before the ride at a Northampton diner. The plan for the day was, “Boys go riding, girls visit museums and shops”. After our atmospheric (but not altogether tasty) fueling stop at the diner, I hightailed it off to the Notch Visitors Center in nearby South Hadley. The weather was perfect, though a little warm; it would eventually reach the high 80s.
The park is a little linear range of mini-mountains with peaks around 1000 feet, just across the Connecticut River from Northampton, probably about 10 miles in length. It’s much higher than the surrounding land, and you can see it from some distance away as you approach it. The range runs along a west/east axis, with a gap in the middle where Route 116 passes through it. The north side of the range is an unrideably steep escarpment (cliffs, really), so most of the trails wind through the jumbled hilly landscape on the south side. Here is an excellent trail map of the area, made by one of the trail builders.
[Continued...]
Icelandic Honeymoon
May 15, 2006 on 10:39 pm | In Uncategorized | 6 CommentsMy wife Max and I just got back from our week-long honeymoon in Iceland. It was quite a trip, both literally and figuratively. I highly recommend it as a destination! It was a bit cold in May, and too soon for some of the tourist facilities and accommodations, but the compensation was that there were no crowds and we could take our time enjoying the spectacles.
You can also check out the photos of the trip on Flickr. I’ve linked to some of the photos, but there are many other pix in the set.
Day 1: Spring Fever
We arrived in Reykjavik on Tuesday morning, after a mere 4-1/2 hour flight from Boston. It was in the upper 60s, sunny, hazy and almost windless. (At the same time, New England was receiving the start of a multi-day pounding of rain leading to this week’s severe flooding.) Everybody was out in T-shirts and shorts, and we soon picked up on the fact that this was a heat wave, Icelandic style. [Continued...]
Software Models, Software Shadows
April 11, 2006 on 1:12 am | In Programming, Uncategorized | No CommentsSoftware engineers like to talk about models, and build them. We build object models, process models, and, when we’re feeling especially clever, model models or metamodels. I think there’s a collective sense in the profession that modeling is a healthy and useful step in understanding… er… whatever it is that we’re modeling. Come to think of it, just what are we modeling when we do all this stuff? Or, to step back even further, what is modeling?
Here’s a rough definition of modeling that I believe many engineers would agree with: “The selection of a set of symbolic representations of real-life entities, relationships, and operations”. It sounds straightforward enough, although we all know the practice can be difficult. We look at real life, identify some things which are going on, and decide how we will map a set of symbols to those things in a hard-edged fashion amenable to some computing. In doing so, we’ll make some choices that we think best reflect “real life”. We won’t get all of it right, but we’ll get some of it right — the part of interest.
Well… I think I don’t believe in that definition any more. [Continued...]
Entries and comments feeds.
Valid XHTML and CSS.
All content copyright (c) 2006-2007 Joseph Berkovitz. All Rights Reserved.