Title: Proxy Post by: Alci on January 27, 2010, 02:42:42 Hello everyone,
Thanks for answering my questions. Here's another problem i encountered during my development with pureMVC: The application i am currently working on need to load different type of xmls from time to time, I want to create a universal xml loader to load the data, then use different VOs to content them. I found the appskeleton demo is useful, but the LoadXMLDelegate uses classes from Flex, I am not sure how this can be done inside Flash. The basic problem i am facing is, if i use a xml loader to load different data, how does it call back the same proxy which called it and transfer loaded xml back to that proxy? (without mx.rpc.IResponder) Obviously I can't create event type for every xml type. Thanks Title: Re: Proxy Post by: puremvc on January 27, 2010, 09:45:49 Use the calling proxy's name as the async token.
First, make the loader itself a Proxy. Lets call it XMLProxy. That way it is accessible to all the other Proxies through the standard mechanisms and has the same lifecycle. In your Proxies that need XML loaded, have them do this: public function fetchXML():void // called from a command or mediator once view is prepped Then in the XMLProxy: public function loadXML( file:String, requestor:String ) Now the only problem is that the data is replaced in the requesting Proxy, but you don't know when it happens. You probably want a notification to go out from each proxy when it gets its data, so that other interested actors know they can now work with that Proxy's data. So inside a requesting Proxy: override public function setData(data:Object):void Note that this Proxy's unique 'got data' note may be going out to let Mediators or a Command know that the Proxy has data and can be retrieved and manipulated. If the interested actors just want the data to work with, include it in this note and they can skip fetching the Proxy. But if you need to use the Proxy's methods to access and manipulate the data, then just the note with no data is sufficient. -=Cliff> Title: Re: Proxy Post by: Alci on January 27, 2010, 09:11:10 wow! that's simple! thank you very much cliff!!!
Title: Re: Proxy Post by: Alci on January 28, 2010, 12:48:47 Ooops, just realized that flash has no RPC
Title: Re: Proxy Post by: puremvc on January 28, 2010, 08:52:15 Oh, sorry. I guess your original mention of IResponder as an option ruled out made me think you were using Flex.
In the case of Flash you need to roll your own Async Token pattern. Here's an article about doing that: http://corlan.org/2008/08/11/extending-actionscript-classes-to-provide-asynctoken-like-behavior/ Following that basic premise, you'd create a custom service component by extending URLLoader, give it an extra property to track your token. For our implementation we'll make a few deviations from that article. We won't pass the token on the constructor, but make it a simple property. And we won't use data for the property name because that's already a property in the superclass. We'll call it token. In the Proxy that uses this service, we'll also make sure that the service isn't interrupted by a new load request by returning a Boolean based on whether the token is set. And we'll clear the token after a result is handled. Your new ServiceWithToken class: package me.myapp.model.service Back in your XMLProxy: public function loadXML( file:String, requestor:String ):Boolean So now there's one extra step for you to consider, which is that your proxies that will use the XMLProxy now need to wait if the XMLProxy is being used. In SomeRandomXMLNeedingProxy: public function fetchXML():void // called from a command or mediator once view is prepped The above is one way to handle that. The fetchXML method will simply knock at the door until someone lets it in. That is until the service call that's pending completes, the data is returned to the appropriate proxy and the token is cleared. -=Cliff> |