Parsley Flex project example

James Hill
tiltdigital
Published in
2 min readMar 7, 2010

I recently had to knock up a demo Flex project using the fantastic Parsley framework from SpiceFactory. Having not used the framework before, I naturally spent a bit of time googling for examples and was disappointed that there actually aren’t many on the web — which is why I’m posting my source here.

The Parsley framework is pretty intuitive and supports some great features including IoC Containers, Dependency Injection with a nice Reflection API. Starting playing with it, it reminded me significantly of the feel of Swiz.

One aspect I particularly like is the messaging system Parsley employs. With Swiz, you were able to dispatch system wide events but to handle them you had to add your listener to the main Swiz singleton. With Parsley, your ‘events’ don’t have to subscribe to the usual flash Event inheritance syntax. Rather, you can ‘dispatch’ any Class as an ‘message’ without said Class extending flash.events.Event.

For example, you may wish to dispatch a NavigationMessage relaying new section info to your main navigation, ie.

class NavigationMessage { public var section:Section; function NavigationMessage ( section:Section ) { this.section = section; } }

Dispatching your message doesn’t have to follow the protocol we’re accustomed to in flash, as we can explicitly declare a parsley MessageDispatcher property, for parsley to Inject an event disptacher into, thus circumventing the need to use the old familiar EventDispatcher…

class SomeClass { [MessageDispatcher] public var dispatcher:Function; function SomeMethod ( section:Section ) void { dispatcher( new NavigationMessage( section )); } }

Then handling your message is as simple as declaring a method with the same input type as the dispatched method and setting the MessageHandler MetaData.

[MessageHandler] function newSectionHandler ( section:Section ) : void

Anyway, I won’t bleat on, but suffice to say, Parsley is really nice framework and I suggest you pop over to SpiceFactory and getting reading up on it’s features. For now I’ll let the code do the talking.

I’ve enable the good old right-click srcview so check out my example and get your nose into the code. Enjoy!

--

--