Hello group, I just started trying to integrate with spring-actionscript today and have run into a small problem. In reading the getting started section of the help file it all looks so simple and straight-forward, but alas I have not been successful at getting a demo up and running.
I am using FlexBuilder 3, Flex SDK 3.3, Flash Player 10 (Debug), and spring-actionscript-0.7.1.
Everything compiles fine but when I deploy and run the Flex application I get this error:
Error: An object definition for 'exampleUser' 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 tested hitting the URL of the applicationContext.xml file and verified that is it present and accessible.
Here is the content of my applicationContext.xml file:
Code:
<?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="exampleUser" class="examples.UserProfile">
<property name="firstName" value="John" />
<property name="lastName" value="Doe"/>
<property name="age" value="41"/>
</object>
</objects>
And here is my application MXML file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initApplication();">
<mx:Script>
<![CDATA[
import examples.UserProfile;
import mx.controls.Alert;
import org.springextensions.actionscript.context.support.FlexXMLApplicationContext;
import as3reflect.ClassUtils;
// Spring ActionScript IOC
private var applicationContext:FlexXMLApplicationContext;
/**
* application complete event handler
*/
public function initApplication():void
{
// create new application context
applicationContext = new FlexXMLApplicationContext();
// define application context configuration file
applicationContext.addConfigLocation("applicationContext.xml");
// register load complete listener and then load the application context XML file
applicationContext.addEventListener(Event.COMPLETE,applicationContext_completeHandler);
applicationContext.addEventListener(IOErrorEvent.IO_ERROR,applicationContext_IOErrorHandler);
applicationContext.load();
}
/**
*
* application context (spring IOC container)
* event handler for load complete
*
*/
private function applicationContext_completeHandler(event:Event):void
{
Alert.show("[IOC] Object definitions loaded: " + applicationContext.numObjectDefinitions.toString());
// instantiate example user object
var exampleUser:UserProfile = applicationContext.getObject("exampleUser") as UserProfile;
Alert.show("[IOC] User Profile=" + exampleUser.firstName + " " + exampleUser.lastName);
}
/**
*
* application context (spring IOC container)
* event handler for IO error
*
*/
private function applicationContext_IOErrorHandler(event:IOErrorEvent):void
{
Alert.show("[IOC] IO Error : " + event.text);
}
]]>
</mx:Script>
</mx:Application>
And finally, my UserProfile class file:
Code:
package examples
{
public class UserProfile
{
private var _firstName:String;
private var _lastName:String;
private var _age:int;
public function UserProfile():void
{
// constructor
}
public function set firstName(value:String):void
{
_firstName = value;
}
public function get firstName():String
{
return _firstName;
}
public function set lastName(value:String):void
{
_lastName = value;
}
public function get lastName():String
{
return _lastName;
}
public function set age(value:int):void
{
_age = value;
}
public function get age():int
{
return _age;
}
}
}
So no matter what I try, I cannot get the spring-actionscript container to instantiate the UserProfile object instance at runtime. The 'applicationContext.numObjectDefinitions' always returns a value of '0'. It make me think the XML is not formed correctly? But I based this example code directly from Chapter 2 @ http://www.springactionscript.org/do...on.html#d4e218
I'm sure this is just some simple oversight, but any help would be greatly apprciated. I'm looking forward to delving further into the IOC and DI implementation but have to get past this first hurdle :-)
I have attached my source project, but to meet the ZIP file size limitations imposted by the forum, I had to remove the following two dependency libraries from the "libs" folder:
- as3reflect.swc
- spring-actionscript.swc
Thank You!