Getting started with Spring Actionscript (Spring IOC/DI for Flex)

I recently started integrating the SpringActionscript (formerly named “Prana Framework”) into my current Flex application. SpringActionscript is an Inversion of Control (IOC) and Dependency Injection (DI) framework for Flex that is syntactically based on the popular Java Spring Framework. While there are several contending IOC frameworks for Flex, if you use Spring in your Java projects it is a natural decision to go with SpringActionscript. Developers that switch between Java and ActionScript can make a mostly comfortable transition without a great deal of ramp up and learning a new syntax.
So I started with a sample project using the current released version 0.7.1 and followed the instructions in Chapter 2 in the Getting Started portion of the documentation. The documentation is straight-forward and pretty clear on what you need to do. However, when I went to run the project, I could never get it to recognize my objects defined in the applicationContext.xml file. It would compile fine, but upon trying to access a named object at run-time (‘bean’ in Java speak) I would get the following error message:
Error: An object definition for ‘exampleObject’ was not found.
at org.springextensions.actionscript.ioc.factory.supp ort::AbstractObjectFactory/getObject()[C:\Users\Christophe\Documents\Adobe Gumbo MAX Preview\spring-actionscript\core\src\main\actionscript\org\spring extensions\actionscript\ioc\factory\support\Abstra ctObjectFactory.as:138]
at SpringActionScriptExample/applicationContext_completeHandler()[D:\repo\trunk\source\SpringActionScriptExample\src \SpringActionScriptExample.mxml:46]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at org.springextensions.actionscript.ioc.factory.xml: :XMLObjectFactory/_doParse()[C:\Users\Christophe\Documents\Adobe Gumbo MAX Preview\spring-actionscript\core\src\main\actionscript\org\spring extensions\actionscript\ioc\factory\xml\XMLObjectF actory.as:343]
at org.springextensions.actionscript.ioc.factory.xml: :XMLObjectFactory/_loadNextProperties()[C:\Users\Christophe\Documents\Adobe Gumbo MAX Preview\spring-actionscript\core\src\main\actionscript\org\spring extensions\actionscript\ioc\factory\xml\XMLObjectF actory.as:315]
at org.springextensions.actionscript.ioc.factory.xml: :XMLObjectFactory/_loadNextConfigLocation()[C:\Users\Christophe\Documents\Adobe Gumbo MAX Preview\spring-actionscript\core\src\main\actionscript\org\spring extensions\actionscript\ioc\factory\xml\XMLObjectF actory.as:291]
at org.springextensions.actionscript.ioc.factory.xml: :XMLObjectFactory/_onLoaderComplete()[C:\Users\Christophe\Documents\Adobe Gumbo MAX Preview\spring-actionscript\core\src\main\actionscript\org\spring extensions\actionscript\ioc\factory\xml\XMLObjectF actory.as:241]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I worked on this issue trying different combinations for a few hours before finally giving into defeat and posting a help request on the SpringSource forums. Within a day the helpful members on the forums quickly pointed out that the namespace and schema defined for the <objects> node in my applicationContext.xml file was using a namespace and schema definition intended for the upcoming 0.8 version release. So it turns out the published documentation is just a little ahead of the game and as soon as 0.8 is released, this should be a non-issue.
Here was my applicationContext.xml file using the namespace and schema locations as defined by the current documentation:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springactionscript.org/schema/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springactionscript.org/schema/objects
http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd">
<object id="exampleObject">
<property name="firstName" value="John" />
<property name="lastName" value="Doe"/>
<property name="age" value="41"/>
</object>
</objects>
An here is my modified, working applicationContext.xml file using the older namespace and schema locations for versions older than 0.8:
<?xml version="1.0" encoding="utf-8"?> <objects xmlns="http://www.pranaframework.org/objects"� xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.pranaframework.org/objects http://www.pranaframework.org/schema/objects/prana-objects-0.6.xsd"> <object id="exampleObject"> <property name="firstName" value="John" /> <property name="lastName" value="Doe"/> <property name="age" value="41"/> </object> </objects>
That’s all it took! All is up and working now.
Here is my full working sample source code project:
For the full details of this issue, please see this forum thread:
http://forum.springsource.org/showthread.php?t=73932




Adobe has significantly enhanced the CSS support for Flex 4 applications. These enhancements include Multiple class selectors, ID selectors, descendant selectors, pseudo (state) selectors.

