An Introduction to Spring ActionScript

DZone 's Guide to

An Introduction to Spring ActionScript

· ·
Free Resource

Finding an Inversion of Control (IoC) container for Adobe Flex and Flash projects that fits all of your needs can be difficult.  Cairngorm and PureMVC both impose a certain structure to your Flex applications, and these structures can negate some powerful features in Flex.   Spring ActionScript is a new IoC container that is supported by SpringSource as a Spring Extensions project.  It's more like a toolbox than an actual framework.  Unlike the previously mentioned IoC's, Spring ActionScript doesn't impose structures.  DZone conducted an exclusive interview with Christophe Herreman, the lead developer of Spring ActionScript, to learn more about this emerging framework.  Herreman works on high-end Flex and AIR solutions

DZone: What is Spring ActionScript?  How does it fit into the ecosystem of related technologies?  What motivated the creation of Spring ActionScript and what other technologies influenced it?

Christophe Herreman:
Spring ActionScript is an open source application framework written in ActionScript 3.0. At its core, it is an Inversion of Control (IoC) container. It can be used for Flex, AIR, Flash or pure ActionScript development.

The IoC container is basically an object/dependency factory that provides a centralized and controlled system for creating objects used in an application. Instead of instantiating objects directly with the "new" operator, the developer can ask the container for an object by its name or its type and provide it to the application. This "Dependency Injection" (DI) can be done by providing the dependencies via the constructor of an object (this process is known as Constructor Injection) or via its accessors/setters (known as Setter Injection).

When coding dependencies behind an interface, the application does not need to know beforehand what concrete types it will use. This has the benefit that the developer can replace the objects with any implementation of the interface at any time. Consider an object that is responsible for loading a collection of users. Whether this is done via a Remote Object, a Webservice, a local Sqlite database or any other mechanism should not be known by the application. All the application should know is that it uses a certain "contract", technically in the form of an interface, to load the users. Using this approach, applications are easier to maintain, extend with new functionality and test because all dependencies are kept and controlled in a central location and easily replaceable.

Spring ActionScript can be used with any other framework. It does not impose a strict architecture but provides the developer with building blocks that can be combined to solve problems specific to the application.

The framework was previously known as the Prana framework and is now incubated as a Spring Extension project by SpringSource, the company behind the original Java Spring framework. It is certainly inspired by Java Spring and borrows a lot of the concepts. This makes it easier for Java developers starting with Flex development because the usage of both containers is almost the same.

DZone: Walk me through how someone would use Spring ActionScript.  What things can they use it for?

Christophe: To start, you would need the compiled library which can be downloaded from www.springactionscript.org. Once that is placed in your build path, you can create an "application context" via one of the IApplicationContext implementations (XMLApplicationContext, FlexXMLApplicationContext, MXMLApplicationContext, ...). Such an application context is an instance of the IoC container running in the application.

The application context then needs to be configured with object definitions. These are blueprints for the objects that the container should create and manage. This configuration can be done either via XML or, if you are using Flex, via MXML. The content of the configuration is then parsed to objects that live in the container. Spring ActionScript will then automatically inject objects into view components or other objects if these are annotated with [Autowired] metadata. It is also possible to do the injection yourself and ask the container for the objects it contains.

An application could then be built and configured to run in different contexts. It could for instance be configured to talk to a server backend using remoting or webservices, or it could be configured to use an offline database. Or, during development, stub or fake implementations could be created so no running server is required. This can be very convenient in large projects where separate teams are working on the server and the client parts.

DZone: What is the current state of the project?

Christophe: The currently released version is 0.8.1 and we are finalizing 0.9 at this moment. We are about feature complete and will improve documentation and samples for the 1.0 release.

DZone: How does Spring ActionScript compare to IoCs?  What makes Spring ActionScript unique?

Christophe: Although there are other IoC containers in the Flash and Flex community, Spring ActionScript's mission statement and vision are quite unique. While most other frameworks focus on Flex development, Spring AS can also be used without the Flex framework. It supports both XML and MXML configuration. It does not impose a strict architecture, but contains all the building blocks needed to create flexible MVC-ish solutions which can be tailored to the problem at hand. Some of these building blocks are the Event Bus, the Operation API, autowiring support, etc.

On top of that, it is perfectly possible to use Spring ActionScript in combination with other frameworks like Cairngorm or PureMVC for instance. In fact, we even have extensions for both Cairngorm and PureMVC that allow configuration of applications built with these frameworks.

In conclusion, we provide developers with a lot of choice without forcing a strict coding style or architecture upon them since we believe and know from our experience that no solution fits all problems. We are open to other frameworks and libraries and want to give the developer options to integrate these into our framework and there applications.

DZone: Tell me about the new features coming in the 0.9 release.  When is the 0.9 release?  What are the future goals of Spring ActionScript?

Christophe: The 0.9 release is scheduled for next week. It's often hard to set strict times since all of the development happens after work hours and in our free time. The release focusses on MXML configuration, improved autowiring and module support. We also have a new sample application that will be distributed with the next release.

We don't have a real roadmap past 1.0. I guess it will all depend on what other frameworks and libraries emerge and if we see opportunities to integrate them with Spring ActionScript. We will certainly improve the framework in any way possible.

DZone: Is there anything you'd like to add?

Christophe: Most of the announcements are published at my blog. We have also started another project (with parts of the codebase of the original Prana framework) called AS3Commons. The project aims to provide highly reusable ActionScript 3.0 libraries like reflection utilities, language utilites, a generic XML parser, a logging framework and many more. Spring ActionScript actually uses some of these libraries under the hood. Even if you are not looking for a framework like Spring ActionScript, I think AS3Commons certainly has something to offer to most ActionScript developers.

To download Spring ActionScript, you can visit the project's website.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}