如果您曾经运行过ObjectBuilder,则实例化的对象将被缓存,下次使用PropertyInjector或其他内容时,将使用实例化的对象而不是创建新对象。或者至少这应该是这样的:)
但是在下面的例子中,似乎伙伴试图再次实例化该对象:
发生以下错误:
! TerminalPresentationModel - constructor called # dispatcher = [object GlobalDispatcher] !
<Injectors (started) target="[class TerminalPresentationModel]" includeDerivatives="false" dispatcherType="inherit" scope="[object Scope]">
<PropertyInjector sourceKey="currentDate" targetKey="date" source="[class DateManager]" sourceCache="inherit" softBinding="false"/>
---------------------------------------------------------
- ERROR: Wrong number of arguments supplied when calling the constructor
- TARGET: TerminalPresentationModel
- TAG: PropertyInjector
- METHOD: constructor
- FILE: TerminalMainEventMap
- NO ARGUMENTS SUPPLIED
- STACK TRACE: ###SHORTENED###
---------------------------------------------------------
---------------------------------------------------------
- ERROR: source is undefined in tag PropertyInjector
- TARGET: TerminalPresentationModel
- TAG: PropertyInjector
- FILE: TerminalMainEventMap
---------------------------------------------------------
- INFO: Data binding will not be able to detect assignments to date
</Injectors (end) target=[class TerminalPresentationModel]>
! DateManager - constructor called # dispatcher = [object GlobalDispatcher] !
<Injectors (started) target="[class TerminalContainer]" includeDerivatives="false" dispatcherType="inherit" scope="[object Scope]">
<ObjectBuilder registerTarget="true" constructorArguments="[object GlobalDispatcher]" cache="inherit" generator="[class TerminalPresentationModel]"/>
<PropertyInjector targetKey="pm" source="[object TerminalPresentationModel]" sourceCache="inherit" softBinding="false"/>
- INFO: Data binding will not be able to detect assignments to pm
</Injectors (end) target=[class TerminalContainer]>
任何暗示我的代码有什么问题?
更新2010-08-16 作为ktutnik的请求,更多细节: 我使用EventMap:
<?xml version="1.0" encoding="utf-8"?>
<EventMap
>
<fx:Script>
<![CDATA[
// imports and namespaces shortened
[Bindable]
public var endpoint:String = "";
]]>
</fx:Script>
<fx:Declarations>
<Debugger level="{Debugger.ALL}" />
<myService:Services id="services" endpoint="{endpoint}"/>
<maps:TimeEventMap endpoint="{endpoint}"/>
<EventHandlers type="{FlexEvent.PREINITIALIZE}">
<ObjectBuilder
generator="{TerminalPresentationModel}"
constructorArguments="{scope.dispatcher}" />
<ObjectBuilder
generator="{DateManager}"
constructorArguments="{scope.dispatcher}" />
<ObjectBuilder
generator="{TerminalFaultHandler}" />
</EventHandlers>
<EventHandlers type="{DataServiceEvent.GET_CURRENT_TERMINAL_STATUS}">
<RemoteObjectInvoker instance="{services.TerminalService}"
method="getCurrentTerminalStatus"
arguments="{[event.locationId,event.actualPlan]}"
showBusyCursor="false">
<resultHandlers>
<MethodInvoker generator="{TerminalPresentationModel}"
method="setCurrentTerminalStatus"
arguments="{resultObject}" />
<MethodInvoker generator="{TerminalFaultHandler}"
method="removeError" />
</resultHandlers>
</RemoteObjectInvoker>
</EventHandlers>
<Injectors target="{TerminalContainer}"
debug="true">
<ObjectBuilder
generator="{TerminalPresentationModel}"
constructorArguments="{scope.dispatcher}" />
<PropertyInjector
targetKey="pm"
source="{lastReturn}" />
</Injectors>
<Injectors target="{TerminalPresentationModel}"
debug="true">
<PropertyInjector targetKey="date" source="{DateManager}" sourceKey="currentDate" />
</Injectors>
<Injectors target="{TerminalContent}">
<PropertyInjector targetKey="faultHandler"
source="{TerminalFaultHandler}" />
</Injectors>
<EventHandlers type="{UnhandledFaultEvent.FAULT}">
<MethodInvoker generator="{TerminalFaultHandler}" method="handleFault"
arguments="{event.fault}" />
</EventHandlers>
</fx:Declarations>
</EventMap>
Flex:4.0 队友:0.8.9
答案 0 :(得分:0)
将debug="true"
放在你的EventHandlers和Injector标签中并查看前一个...尝试将CreationComplete事件组合起来,而不是PreIntitialize。如果我在Application CreationComplete中没有弄错,早于Preinitialize(但我真的不确定..因为它也让我感到困惑)。
答案 1 :(得分:0)
似乎你不能在一个EventMap中拥有两个ObjectBuilder。这将导致此问题。 当我在Preinitialize-Event中删除ObjectBuilder时,一切正常。
这是一种奇怪的行为,因为在其他地方我写的就像这种情况一样,没有问题发生。 所以我真的不知道为什么它有效,但它似乎解决了我的问题。