AS3/Flash 9/Firefox Mouse Capture Bug
Ran into an unfortunate problem with ActionScript 3 and the Flash 9 player, when running inside Firefox on a Mac (Firefox 2.0).
I've created an interactive that allows the user to essentially 'throw' the canvas around. The user clicks, drags, and lets go. Depending on the velocity of their drag at the time they release, the canvas will scroll and pan accordingly. This functionality relies on the ability to detect when they release the mouse, especially when they happen to release outside the stage/movie.
This was accomplished easily with onReleaseOutside in AS2. Now with AS3 you simply add an event listener for "mouse up" on the stage and in principal it should give you what you need. Unless of course you are either using Firefox 2.0 on MAC or your movie is using a non-standard 'wmode' setting.
On Firefox 2.0/MAC/Flash 9 for instance, any Flash 9/AS3 component like a slider, button, (or my friggin application) will track your mouse just fine if you mouse outside the bounds of the movie -- but if you let go of the mouse outside the movie, Flash has no clue (inspecting buttonDown property of mouseMove event event reflects that its still pressed). If you then mouse back over the movie, it thinks you still have the button pressed so it still moves the slider back and forth, etc.
Horrible show stopper unfortunately. Not sure where to even file a bug. Back to AS2 I guess... what a shame. I was so enjoying E4X and event propagation.
UPDATE: Stumbled upon a workaround after much trial and error. At least until they fix mouse_up.
So there's a mouseLeave event... unique to the stage object. This event is dispatched under normal circumstances as soon as your cursor leaves the bounds of the player window. But... if you've moused down first, then dragged outside window, the mouseLeave is not fired *until* Flash is done tracking. In other words, until the user lets go of the mouse button.
So now I listen for *both* mouse up and mouseLeave on the stage object and I can reliably (cross browser), detect when the user has released the mouse button in the case the cursor is outside of the stage. In this scenario I only attach the mouseLeave and mouseUp listeners on the stage after the user has first moused down. I then remove them once I've detected the mouse up.
Still hoping for a fix, but at least this provides an alternative (albeit sneaky) work around.
Labels: actionscript 3, as3, firefox, mac, mouse, onReleaseOutside

