Monday, January 3, 2011

Invalidation for every nation object

Invalidation for every nation object:

In writing the destroy-menu library, I stopped to think how I could incorporate invalidation in non-display objects. I treat menus like views, providing each with its own mediator, but since menus lack a stage, the mediators require manual instantiation. The lack of a stage also affects invalidation since AS3′s standard invalidation method, stage.invalidate(), is owned by the Stage class. A few alternatives exist, but which one provides solid functionality, proper timing, and ease of implementation? I’ll share my thoughts on the matter, but I’d really like to start a discussion with this post, so feel free to give your two cents.

stage.invalidate()

As indicated earlier, stage.invalidate() is the standard when invalidating display objects. You call the method, listen to Event.RENDER on the Stage and remove the listener in the handler. Using RENDER ensures invalidation finishes prior to drawing the Stage. If you have ever used this method, you know it’s not perfect. A gotcha exists if you ever call stage.invalidate() within the RENDER handler. What happens? Nothing. There is one workaround that involves listening to Event.ENTERFRAME along with RENDER, so any leftover code will execute after the frame renders.

In order to use stage.invalidate() with non-display objects, you’ll need to inject a Stage into the objects, which might be tedious if you’re not using automated injection. Also, if you’re one for semantics, tying a Stage to non-display objects makes as much sense as garlic mints [...]

No comments:

Post a Comment