AS3 MOUSE_LEAVE no longer reliable

December 8th, 2010

Looks like certain browsers have updated mouse events so that MOUSE_MOVE works outside of the bounds of an swf on a page. This is really nice, but other mouse events do not seem to function properly. MOUSE_UP for example does not seem to get called in safari, and only gets called in chrome after an additional movement of the mouse. This becomes a kind of sticky situation for something like a scrollbar or object that you are using MOUSE_DOWN to gain focus and then looking at the stage to stop the mouse updates based on MOUSE_UP. The solution used to be to resign focus on MOUSE_LEAVE, but this does not appear to be firing. The only 2 things I could think of to do in these situations were to use javascript mouse events (which may not be a possibility based on the project) or 2 to force resignation of the mouse when leaving the stage.

In the mouse move handler I put:
if(mouseX > stage.stageWidth || mouseX < 0 || mouseY > stage.stageHeight || mouseY < 0){
// stop mouse move action

It does work, but it seems like a crappy approach. I will need to look and see if there's any documentation on this *feature* to see if there's another alternate approach to get a global mouse up event when the mouse is outside of the swf.

IOS file browser

November 11th, 2010

After wondering why there wasn’t a file picker in IOS I decided to just make one that I could reuse in my projects. All it does is open a file dialog that puts you in the application’s documents directory and lets the user create folders and manage their own structure. Implementation is simple, the steps are:

1. Pass in either a file you want to save, or a list of extentions you want to load.
2. Present the file browser as a modal view controller.
3. Add delegate methods to handle the response of the file browser.

I tried to build it to be modified as easily as possible. All of the buttons are dealt with in a couple of .xib files so that anyone who would like to use it could easily skin it.

You can grab the source here.

Texture Atlas Creator

November 1st, 2010

Daniel over at Sparrow wrote up an article on how to use the flash based texture atlas creator I built. I figured I would at least put a public link in here so that folks can find it. Here’s the link

Scoping in javascript

October 11th, 2010

Not sure why I don’t see more addressing this on the internet, but when you make an object in javascript and want to call the methods it contains via event listeners all the method calls fall out of scope, making instance variables out of scope as well. I have done all kinds of weird things to get around this in the past, until one of my coworkers set me up with this method:

function CreateDelegate(object, method) {
return (function() { return method.apply(object, arguments); })

Nice to have easy to use and light. I don’t need to import any external libraries.

Sparrow Framework

September 22nd, 2010

I’ve been playing around with the Sparrow framework which is pretty amazing. I like Apple’s framework for dealing with forms and data driven content, but when it comes to graphics their stuff on it’s own feels really mixed up. Most of the time I am wondering if I should be using Quartz or Core Animation and end up finding that what I need to do is just best handled in OpenGL. Sparrow handles a lot of boilerplate things, it’s very fast and best of all it integrates well with apple’s other components. If you just want an interactive scene that does a lot of 2D stuff you just add it as a subview and start/stop as needed. It has easing, audio, fonts and movieclips, is modeled off the flash display hierarchy (which I think is flash’s biggest selling point) and even adds in event listeners.

The code for Sparrow is very very cleanly written, and is lean enough to look through but seems to hit all the core features I would want. I also found it a lot easier to start tinkering with their libraries than I did with cocos2D. The start up documentation gets you up and running in a matter of minutes. With all the drama about flash and the crap performance this is really a nice solution that plays nice with the rest of Apple’s framework.

Kudos guys.