Monthly Archive for April, 2009

Bubbling events in data models

I’ve been using moccasin for a bit now on a smallish project.  One of the cool things it does is give you a sort of event bubbling in your datamodel.  While moccasin is a very specific framework for a very specific sort of application, the more I think about it, the more I like the bubbling-events in the data model part as a general solution to a wider variety of problems.

Let’s look at a very simplified example that illustrates the general idea (actual mocasin implementation varies quite a bit from this).  Imagine this code…

  1.  
  2. public class PizzaModel
  3. {
  4.   [Bindable] public var sauce:PizzaSauce;
  5.   [Bindalbe] public var size:Number;
  6. }
  7.  
  8.  
  9. [Bindable] public class PizzaSauce
  10. {
  11.   public var name:String;
  12.   public var displayColor:uint;
  13. }
  14.  
  15.  
  16. public class PizzaView extends UIComponent
  17. {
  18.   public function setPizza( pizza:PizzaModel )
  19.   {
  20.      pizza.addEventListener(ModelChangeEvent.MODEL_CHANGE, onModelChange);
  21.   }
  22.  
  23.   protected function onModelChange(event:ModelChangeEvent):void
  24.   {
  25.     switch( event.property )
  26.     {
  27.        case "size": // the pizza size changed, handle that.
  28.  
  29.        case "sauce/displayColor": // the sauce color changed, handle that.
  30.  
  31.        default: // some property that we can’t incrementally
  32.                   // update changed, handle that…
  33.  
  34.     }
  35.   }
  36. }
  37.  

We have some kind of model object, let’s call it the PizzaModel.

That model has a property, that itself is some kind of complex object.  Lets call that property sauce, and the type will be called PizzaSauce

Now, we have some kind of view object.  Let’s call it the PizzaView.

A normal way to implement something like this would be to have the pizza view listen to events on both the pizza object and it’s sauce object. Or it could manually set up some change-watchers that watched the hierarchy to the required properties.

That’s all fine and dandy until we get to more complex object hierarchies. What if we had an arraycollection of toppings and we needed to know when individual properties of those toppings changed? Now, we’d have to listen to yet another type of event.

And what happens of those toppings themselves had lists of ingredients we wanted to listen to, suddenly the event chain is getting pretty gnarly to manage.

If we had some kind of magical bubbling model event, we’d only have to listen at a single location, as shown above. Especially if there was an expressive way of identifying what changed.

How might something like this be implemented?

Mocassin does it by having a meta-data model that wraps the actual data model and provides this extra functionality.

Another way would be to force the data model objects to all extend from a common superclass (I believe earlier versions of Moccasin did just that)

Someday, I’d like to explore either creating a general purpose framework for this or extracting it from Moccasin. I’m blogging about it hoping someone might do it before I get a chance ;)

How far does your email address go back?

A random thought occurred to me today when an email to a friend bounced back.  We seem to change email addresses far more frequently than phone numbers, physical addresses, or most other contact methods.  Looking in my GMail account, the oldest email I still have goes back to 6/18/2004.  But for email addresses, one of the addresses that I still regularly check was first in use all the way back to September of 2000.

So what’s YOUR stats for

a) Oldest email you have sitting around that you can easily access without pulling out a backup tape or archive CD?
b) The oldest email address that you still regularly check?

While 5 years for an email and 8.5 years for an address seem like a long time, think of how short those are compared to carvings in a rock…

I’m on twitter now…

Seems like the thing to do, so I’m on twitter now.

Essential Guide sample chapter

Just visited the Friends of Ed website for the Essential Guide on Open Source Flash Development and noticed they used one of my chapters as a sample-chapter you can download.  Neat.

ADigitalBook, another ObjectHandles usage

Rui over at http://www.adigitalbook.com/ wrote me to tell me he’s made extensive use of Object Handles to build their application.  It’s a photo album creator done up in an AIR app with Here’s a couple screenshots:

Also, I noticed they did a neat thing with integrating their newsletter signup with the AIR download badge.

Bookpool RIP?

I went to buy a book today at Bookpool and came up with this:

Bookpool is (was?) a great little site that specialized in technical books.  They had a good selection, and amazingly fast shipping.  They also employed me a few years back.  They had been around a really long time, it’s a shame if they’re gone, hopefully it’s just a technical problem.

5/8/2009 – Credible update from the comments below, a little more information.

Easy object reflection with Spicelib

I use Parsely in some of my projects for an MVC / IoC framework.  Parsley relies on Spicelib, so you get that functionality “for free” if you’re using Parsley.  Lately, I’ve started using some of the Spicelib relflection API and I’m impressed with it.  It acts as a wrapper around the flash.utils.describeType method to describe objects at runtime.

Here’s an example that loops through the properties of an object…

  1. var ci:ClassInfo = ClassInfo.forInstance( component );
  2. for each ( var property:Property in ci.getProperties() )
  3. {
  4.   trace( property.name );
  5.   trace(property.type.name );
  6.   trace( property.readable );
  7.   trace( property.writable );
  8. }

You can get a whole lot of info about classes, methods, and properties, you can read the docs to see.

One useful function of this, is you can get at any custom metadata tags that you’ve created.  In that loop above, I could have something like this:

  1. for each ( var meta:Metadata in property.getAllMetadata() )
  2. {
  3.   if( meta.name == "AnimationProperty" )
  4.   {
  5.     // do something with this property
  6.   }
  7. }

Then, if I had a class like this:

  1. public class StupidClass
  2. {
  3.     [AnimationProperty]
  4.     public var thisIsAnAnimationProperty:Number;
  5.  
  6.     public var thisIsNOTAnAnimationProperty:Number;
  7. }

We could differentiate between those two properties.

Read this blog entry for a little info on how to do custom metadata.