如果您運行ObjectBuilder,則實例化的對象將被緩存,並且下次使用PropertyInjector或其他方法時,將使用實例化對象而不是創建一個新的對象。或者至少,這應該是這樣的:)Flex/mate:mate不會緩存使用Object Builder創建的實例
但在它下面的例子看來,隊友試圖再次實例化對象:
出現以下錯誤:
! 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 requestes,更多的細節: 我使用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>
軟硬度:4.0 隊友:0.8.9
你的代碼似乎對我很好..很奇怪.. – ktutnik 2010-08-16 14:34:51