OK! I had time to play some with Mate and my example, and I finally got a scheme that may just work without using a 'global' Singleton instance reference. Yes I can be slow, but ... So here is what I have: 1) Main MXML loading a MainUIViews MXML with a simple mx:List. 2) Main also has a MainEventMap MXML. 3) MainDataManager MXML to store system state data. 4) The normal other stuff like events, utilities, vos, etc... So the MainEventMap first instantiates my MainDataModel into Mate's cache. This eliminates my need for the Singleton.getInatance() method, ...hopefully. Once instantiated, the XML data is ordered, HTTPServiceInvoker - here just an XML file. //------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" > <mx:Script> <![CDATA[ import views.*; import models.*; import mx.events.FlexEvent; import mx.collections.XMLListCollection; import mx.controls.Alert; // Event map local utility functions. private function XMLResultsConverter( xml:XML ):XMLListCollection { return( new XMLListCollection( xml..image ) ); } private function XMLServiceFault( fault:String ):Alert { return Alert.show("Error: ...bad HTTP call. /n"+fault); } ]]> </mx:Script> <Debugger level="{Debugger.ALL}" /> <!-- FlexEvent.PREINITIALIZE --> <EventHandlers type="{FlexEvent.PREINITIALIZE}" debug="false" > <ObjectBuilder generator="{MainDataManager}" > <Properties globalDispatcher="{scope.dispatcher}" /> </ObjectBuilder> </EventHandlers> <!-- FlexEvent.CREATION_COMPLETE --> <EventHandlers type="{FlexEvent.CREATION_COMPLETE}" debug="false" > <HTTPServiceInvoker id="get_XML_db" url="./image_db.xml" useProxy="false" resultFormat="e4x" debug="false" > <resultHandlers> <InlineInvoker method="XMLResultsConverter" arguments="{[resultObject]}" /> <ObjectBuilder generator="{MainDataManager}" > <Properties XMLDataLC="{lastReturn}" /> </ObjectBuilder> </resultHandlers> <faultHandlers> <InlineInvoker method="XMLServiceFault" arguments="{[fault]}" /> <ObjectBuilder generator="{MainDataManager}" > <Properties alert="{lastReturn}" /> </ObjectBuilder> </faultHandlers> </HTTPServiceInvoker> </EventHandlers> <!-- BINDINGS: XML Data Injector --> <Injectors target="{MainUIViews}" > <PropertyInjector targetKey="XMLDataLC" source="{MainDataManager}" sourceKey="XMLDataLC" /> </Injectors> </EventMap> //------------------------------------------- In the resultHandlers, I first use an InlineInvoker that simply converts the resultObject, XML, to an XMLListCollection that is passed along as the SmartObject, lastReturn. The next step is an ObjectBuilder using the cached MainDataModel to store this XMLListCollection. In the MainDataModel I used getters/setters and bind them: [Bindable] public dynamic class MainDataManager implements IEventDispatcher { //------------------------------------------- // Main UI views model data storage elements... private var _XMLDataLC:XMLListCollection; public function get XMLDataLC( ):XMLListCollection { return _XMLDataLC as XMLListCollection; } public function set XMLDataLC( value:XMLListCollection ):void { _XMLDataLC = value as XMLListCollection; } //------------------------------------------- Now in the MainUIViews, I have added a bindable local variable, XMLDataLC, which is used as the data provider for my MX:List: <mx:Script> <![CDATA[ import mx.collections.XMLListCollection; [Bindable] public var XMLDataLC:XMLListCollection = new XMLListCollection(); ]]> </mx:Script> <!-- Simple list of images --> <mx:List id="mainDataList" width="300" height="400" dataProvider="{XMLDataLC}" labelField="file" /> Finally, the injectors in the MainEventMap push the image file data into the list: <!-- BINDINGS: XML Data Injector --> <Injectors target="{MainUIViews}" > <PropertyInjector targetKey="XMLDataLC" source="{MainDataManager}" sourceKey="XMLDataLC" /> </Injectors> Well, so far, it all works thanks to the help that all have provided. TY I hope that this is as it was meant. Comments welcomed. Greg http://www.gypsytrader.com/mate/post01.txt http://www.gypsytrader.com/mate/image_db.xml
mate-objectbuilder
最新推荐文章于 2024-03-07 07:45:00 发布