Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.
justsee edited this page Sep 13, 2010 · 38 revisions

A Lightweight, Enjoyable Framework for ActionScript

Dawn is a lightweight framework for ActionScript inspired by Google Guice. In addition to Dependency Injection, it provides type safe notifications and helps you to build apps which are loosely coupled, easily unit tested, and less error-prone.

If you’ve become frustrated with verbose and fragile frameworks, give Dawn a chance and we promise you will have at least 30% more fun!

Dependency Injection?

There’s really nothing to it, promise. While we’re promising, we will say that Dependency Injection (DI) makes it easier to build and test your apps. DI simply means instead of littering your classes with new:

 var bicycle:Bicycle = new Bicycle();

You let Dawn inject it for you:

[Inject] public var bicycle:Bicycle;

Metadata (like the [Inject] above) is at the heart of the DI and Notification system in Dawn. Nothing tricky here: Adobe provide many metadata tags for the language, and Google uses the same approach for Guice (though in the Java world they call them annotations).

Once you forget new, and embrace DI, you’ll start to find testing and rearranging your app is a whole lot more fun!

Type Safe Notifications…Tell me more

In other frameworks, it’s all too-common to see something like this:

 var foo:Foo = notification.getBody() as Foo;

The notification system in Dawn avoids this situation by explicitly calling a listening object’s method with the appropriate arguments. If an object is interested in a particular notification, it implements the appropriate interface which describes the contract for that notification:

public class Foo implements IBar {

 public function Foo(){
 }

 public function doSomething( wibble:Wibble ):void {
   // do something
 }
}
public interface IBar {
  function doSomething(wibble:Wibble):void;
}

Then it’s simply a matter of letting Dawn know that an object wants to handle notifications, by telling the INotificationBus:

 bus.addHandler( foo );

Whenever a notification is triggered, Dawn checks whether each handler is interested in the notification, and if so calls it’s handler, via the Notification which was triggered:

Right, Lets Get Started!

DawnBasics

Clone this wiki locally