I’ve just built a cool new print feature into Workout Week—the ability to print foldable pocket guides that list your entire workout schedule for the week. It’s a pocketmod–inspired idea, and it makes a lot of sense to provide a workout schedule you can realistically take with you to the gym. I’ll continue to refine the pocket guides as I develop the site, but it’s nice to throw up a quick 1.0. Check out the guide for the cross-training schedule here, or click the print button on any workout schedule. Below I’ll talk a bit on the implementation details, and what could be done to speed things up.
I built the pocket guides using Flash 8—they all dynamically pull their content from the XML files behind each workout schedule, so theres no additional support work on my part to keep them running.
I first set out using Flash to pull data from the XML file directly. After hours of frustration, I wound up choosing a PHP solution to serve flash data as a flat variable list. The XML parser built into Flash is horribly slow and buggy compared to the amazing simple_xml in PHP. Flash breaks when you don’t inform it of unexpected XML comments or type declarations, and the debugging tool was completely useless in this regard.
However, when it comes to printing, Flash is amazing. The printJob class (which I believe is new in Flash 8 ) makes it incredibly easy to define exactly what part of the frame to print, even if its outside the visual area of the frame. The entire pocket schedule actually renders in the flash movie, but it is hidden outside of the visual area - leaving only the “Print Guide” button showing. Using printJob, I was able to tell Flash to only print the hidden schedule, leaving the button outside of the printed version.
I’m not completely satisfied with the rendering performance of the pocket guides, and there are some obvious glitches in this first release.
First off, the PHP pre-processor I’ve written is not optimized for the job. Flash makes seven separate load calls to the PHP pre-processor script to grab all the schedules for every day of the week. This can easily be re–written to use only one PHP call, which I’ll fix sometime this weekend.
The pre–loader for the Flash doesn’t wait for the external PHP script to be called. This can cause some days of the week to not load into the guide before the print button is called. Again, this will be fixed simply by optimizing my PHP calls.
Finally, because of the way I’ve written the code today, the PHP code isn’t easily cachable, making it difficult to scale. Refactoring the PHP and Actionscript will go a long way towards making the site more scalable. Update: 2/24 — I’ve re-written the PHP pre-processor and Flash loader to make the pocket guides load faster.
I’ll be adding the ability to submit custom exercises to be viewed and rated by everyone in the coming weeks. Before I release this I want to make sure I’ve got enough users to actually make a community-type feature worthwhile to the users.
[tags]flash, php, exercise, workout, xml[/tags]

