Apparat – A custom Matryoshka
A few weeks ago Joa Ebert (@joa) released an update to the Apparat Reducer, adding the option of LZMA compression to further reduce your SWF file-sizes.
It works by squeezing your original SWF with LZMA compression, and injecting that data as a ByteArray into a wrapper SWF - hence the Matryoshka moniker.
The Matryoshka handles decompressing the data with an AS3 implementation of LZMA decompression, and then loads the resulting SWF bytes with a standard Loader object.
This all works beautifully, and you can get pretty decent reductions in file-size, especially on larger SWFs.
After testing it, I took a look at the Apparat sources - in particular the LZMA decoder and Matryoshka wrapper - and noticed that because of the use of the Vector type, the code was only compatible with Flash Player 10 or greater.
With the need to create Flash Player 9 compatible content still the part of many a working day, I felt it was worth trying to build a custom version of Apparat with Flash Player 9 compatible Matryoshka and LZMA decompression...
Inside the Apparat...
The following guide to modifying and building a custom version of the Apparat framework assumes you've had a play with Apparat and don't mind using the command line to run some builds.
In addition to the standard Apparat setup (Java, Scala, ANT, ...) you'll need a version of Mercurial - to get a local clone of the Apparat project source, and Maven - Apparat builds require maven-3.0-beta-1
Once you have the source set up somewhere suitable, the two Apparat modules you'll need to modify (if you want Flash 9 compatible LZMA/Matryoshka, that is) are: apparat-lzma-decoder, and apparat-matryoshkas.
For me, simply replacing all Vector.<Type> references with Array worked a treat. Although you'll have to be aware that when changing between Vector and Array, the constructors are different:
v = new Vector.<Type>(size:uint, fixed:Boolean);
a = new Array(size:uint);
Since the "fixed" parameter does not exist for an Array, it will be taken as the second value to store and the size/length will not be set.
Building your custom Apparat
After setting up Maven (extract and add to your PATH environment variable) you're ready to set-up the Apparat project. From the Apparat source root, run:
mvn clean install
This will download all the required dependencies to your local repository, and may will take some time. When Maven has finished doing its thing, you're ready to start building.
To check your earlier modifications haven't broken anything within Apparat, you can build individual modules before compiling the whole project. For example, to check the apparat-lzma-decoder still compiles, run the following from that directory:
mvn compile
Once you're ready to build and package up your custom version of Apparat, run the following in the project root:
mvn package assembly:assembly
And that's it! After a little while, the ready to use apparat-aggregator zip/bz2/gzip deployment files will be copied to the /target folder.
A final "Thanks!" has to go to @joa for pointing me in the right direction in the first place, getting back to me so promptly when I needed help, and of course, for Apparat itself












[...] This post was mentioned on Twitter by Joa Ebert, Mike Almond. Mike Almond said: Blogged: Building a custom Apparat – supporting LZMA/Matryoshka compression in Flash Player 9 http://j.mp/bs7DHV [...]
Brilliant Stuff Mike.