content of The application-content.xml is
[code="java"]<?xml version="1.0" encoding="utf-8"?>
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">
<property file="strings.properties" />
<object id="string1" class="String">
<constructor-arg value="${s1}"/>
</object>
<object id="string2" class="String">
<constuctor-arg value="${s2}"/>
</object>
[/code]
content of strings.properties is:
[code="java"]s1=Firststring
s2=Secondstring
[/code]
[code="java"]
Main Thread (Suspended: Error: An object definition for 'string1' was not found.)
org.springextensions.actionscript.ioc.factory.support::AbstractObjectFactory/getObject
SpringActionScript/test
SpringActionScript/onCreationComplete
SpringActionScript/___SpringActionScript_Application1_creationComplete
flash.events::EventDispatcher/dispatchEventFunction [no source]
mx.core::UIComponent/dispatchEvent
mx.core::UIComponent/set initialized
mx.managers::LayoutManager/doPhasedInstantiation
Function/http://adobe.com/AS3/2006/builtin::apply [no source]
mx.core::UIComponent/callLaterDispatcher2
mx.core::UIComponent/callLaterDispatcher2
mx.core::UIComponent/callLaterDispatch[/code]
我是最新的版本, 配置 property 就出上面的错误,有哪位遇到过?
附件是代码。
不好意思,发错了
是
<?xml version="1.0" encoding="utf-8"?>
creationComplete="onCreationComplete()"
xmlns:mxml="org.springextensions.actionscript.context.support.mxml.*">
mx:Script
<![CDATA[
import com.sgb.model.MyClass;
import org.springextensions.actionscript.context.support.XMLApplicationContext;
private var _applicationContext:XMLApplicationContext;
private function onCreationComplete() : void {
// _applicationContext = new XMLApplicationContext("application-context.xml");
// _applicationContext.addEventListener(Event.COMPLETE, onApplicationContextComplete);
// _applicationContext.load();
test();
}
private function onApplicationContextComplete1(event:Event):void {
var xx:MyClass= _applicationContext.getObject("nlslzf") as MyClass;
xx.p();
}
private var applicationContext:XMLApplicationContext;
private function test():void
{
applicationContext = new XMLApplicationContext("application-context.xml");
//applicationContext.addEmbeddedConfig(contextConfig);
applicationContext.load();
applicationContext.addEventListener(Event.COMPLETE, onApplicationContextComplete);
}
private function onApplicationContextComplete(event:Event):void {
var str:String= applicationContext.getObject("string1") as String;
var xx:MyClass= applicationContext.getObject("nlslzf") as MyClass;
xx.p();
}
]]>
</mx:Script>
看看例子
http://nlslzf.iteye.com/blog/315223
基本上你什么也没写,怎么解决错误啊???
“3.一般情况下,flex源代码目录下,增加一个xml配置文件”,你这个配置文件放哪个目录了?
private function onCreationComplete() : void {
_applicationContext = new XMLApplicationContext("application-context.xml");
_applicationContext.addEventListener(Event.COMPLETE, onApplicationContextComplete);
_applicationContext.load();
}
private function onApplicationContextComplete(event:Event):void {
var xx:Object= _applicationContext.getObject("nlslzf");
var getProductsEvent:GetProductsEvent = new GetProductsEvent();
getProductsEvent.dispatch();
}
注意看我的代码,你的demo中的代码我看了,绝对不能够写到一起,flex对于文件操作一般都是异步的
<?xml version="1.0" encoding="utf-8"?>
creationComplete="onCreationComplete()"
xmlns:mxml="org.springextensions.actionscript.context.support.mxml.*">
mx:Script
<![CDATA[
import com.sgb.model.MyClass;
import org.springextensions.actionscript.context.support.XMLApplicationContext;
private var _applicationContext:XMLApplicationContext;
private function onCreationComplete() : void {
// _applicationContext = new XMLApplicationContext("application-context.xml");
// _applicationContext.addEventListener(Event.COMPLETE, onApplicationContextComplete);
// _applicationContext.load();
test();
}
[Bindable]
[Embed(source="application-context.xml",mimeType ="application/octet-stream")]
public var contextConfig:Class;
private function onApplicationContextComplete(event:Event):void {
var xx:MyClass= _applicationContext.getObject("nlslzf") as MyClass;
xx.p();
}
private function test():void
{
var applicationContext:XMLApplicationContext = new XMLApplicationContext();
applicationContext.addEmbeddedConfig(contextConfig);
applicationContext.load();
var str:String= applicationContext.getObject("string1") as String;
var xx:MyClass= applicationContext.getObject("nlslzf") as MyClass;
xx.p();
}
]]>
</mx:Script>
这是我给你改好之后的代码,在我这里可以,另外把你的strings.properties文件复制到bin-debug目录下,否则会报错