I just returned from a trip round SE Asia to see my last project launch. Called ‘A History of the World in 100 Objects‘, it’s a joint venture between BBC Radio 4 and the British Museum to chart human history in a new way. I developed the concept for the Flash 3D object explorer with the guys at GT and built it using Flash 10’s native 3D capabilities. Users are able to explorer objects from throughout human history in a sort of 3D timeline and even make history by adding their own. Here’s the TV advert for the series:
Since it is expected to grow to up to 10,000 objects over the next 5 years, I used all the tricks in the book to optimise loading, rendering and memory management – which will bore most people to tears, so that’s for another time. Check out the Flash site itself here.
I recently stumbled over a new AS3 gotcha that seems to be bugging a lot of the Flash community. Apparently a new 'feature' of AS3, whereby using the mousewheel inside an embedded Flash movie still scrolls the surrounding browser window (if it has enough content, that is).
This didn't happen in AS2. If a Flash movie had focus, mousewheel events weren't sent to the browser window. It wasn't a problem in FireFox either, until a recent update and adversely affects any AS3 Flash app embedded in an HTML page where you might want to scroll or zoom with the mousewheel while over the Flash, instead of the scrolling the browser window.
So, I decided to cook up some code to fix this. While it's early version and isn't perfect, it suits my purposes, is easy to set up and doesn't require any external JavaScript - so I'd thought I'd share it with the world, in case Adobe never get around to addressing this 'feature'.
Introducing MouseWheelTrap. A handy little utility class that traps mousewheel events while the mouse is over the Flash, so your app scrolls how it was intended to. I've tested it with SWFObject on PC IE and FireFox, but not with SWFMacMouseWheel on Mac (if someone could tell me if it works). I decided against using jQuery for trapping mouse events, partly out of laziness, partly because many people have no control over the HTML that embeds their Flash app and therefore can't add custom JavaScript.
Unzip the package and have a look at the demo, or just take the MouseWheelTrap.as file and put it in the com.spikything.utils folder into your own project or classpath.
Import the utility and set it up somewhere in your main class like so:
I've seen a few people get into a pickle over this one. When you're developing and testing locally, you need to set the 'Local Playback Security' setting (sometimes referred to as the 'use network services' option) depending on whether you wish to access local external files (e.g. XML files, or images) or some other server (e.g. your dev backend server). You can't access both from a locally running SWF anymore, since it's a security risk. So here's how to set that option in Flash CS3 / CS4 or from within FlashDevelop.