Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: event firing two times.  (Read 13667 times)
gwinnem
Newbie
*
Posts: 9


View Profile WWW Email
« on: November 04, 2009, 06:20:29 »

I have a proxy with a delegate class loading a xml file using HTTPService.
The proxy implements the IResponder interface and an instance of the proxy is passed to the delegate class.
My problem is that the proxy's result function is fired twice and the same with the fault function if the loading fails.
Anyone have any idea why ?

Proxy code:
        override public function onRegister():void
        {
            if (Log.isDebug())
                logger.debug("onRegister");
            var delegate:DefaultModuleLoaderDelegate = new DefaultModuleLoaderDelegate(this);
            delegate.loadModuleConfig();
        }

Delegate code:
        /**
         * Constructor.
         * @param responder IResponder from caller.
         */
        public function DefaultModuleLoaderDelegate(responder:IResponder)
        {
            if (Log.isDebug())
                logger.debug("Constructor");
            this.service = new HTTPService();
            this.service.contentType = HTTPService.CONTENT_TYPE_XML;
            this.service.url = XMLFILE;
            this.service.resultFormat = HTTPService.RESULT_FORMAT_E4X;
            this.responder = responder;
        }

        /**
         * Worker function. Responsible for loading xml file.
         */
        public function loadModuleConfig():void
        {
            if (Log.isDebug())
                logger.debug("loadModuleConfig");
            try
            {
                token = this.service.send();
                //Making sure the response is delegated upwards.
                token.addResponder(this.responder);
            }
            catch (error:Error)
            {
                if (Log.isError())
                    logger.error(error.getStackTrace());
                ExtendedAlert.showExtended("defaultmodule.xml is missing.", "Fatal error", 4, null, null, ExtendedAlert.ICON_ERROR48, 4);
            }
        }
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: November 04, 2009, 08:09:58 »

Sounds like you've upgraded to Flex 4 beta 2, where Adobe has inadvertently introduced a bug that leads to this behavior. Have a look at this thread for details:

http://forums.puremvc.org/index.php?topic=1521.0

-=Cliff>
Logged
gwinnem
Newbie
*
Posts: 9


View Profile WWW Email
« Reply #2 on: November 04, 2009, 12:05:58 »

Hi Cliff, im running flexbuilder 3 eclipse plugin with framework 3.3


Geirr
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: November 05, 2009, 09:38:13 »

Actually, the bug1 indicates that it hasn't been regression tested. This means it was reported for Flex 4 beta 2, but Adobe hasn't tested earlier versions yet to see when it was actually introduced.

Some folks on the discussion list for the bug have indicated that they've seen it in Flex 3.4 SDK. You may want to chime in that you're getting it in 3.3.

I'm fairly sure this isn't a PureMVC issue.

-=Cliff>

1http://bugs.adobe.com/jira/browse/SDK-22333
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #4 on: November 06, 2009, 01:12:57 »

Sorry to pollute the thread with my off-topic question. But, Cliff, this is a long time unanswered question for me. Does using Delegate as gwinnem does using the proxy as IResponder is the good solution to use Delegates in PureMVC? Any other advice, good examples regarding Delegates in PureMVC?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: November 06, 2009, 09:01:29 »

You can see Delegate usage in several demos, including Cafe Townsend.1 I also used one just for fun in the DeploymentConfig utility. 2

But really, there's no need for it. It could be useful if you have more than one Proxy using a service.  But really, it's use is promulgated by Cairngorm developers, who are making their calls from Commands, short lived objects.

Proxies are long-lived objects which can instantiate the service once and call it many times thereafter without need for setup.

In a Proxy's onRegister you instantiate the service and add listeners for all the result and fault methods. Remember there may be multiple service methods being called (on a RemoteObject) so you may have several handlers. So I don't like to implement IResponder, forcing me to have just one result and one fault handler. Just add listeners in onRegister and remove them in onRemove (if the Proxy will be removed before the program ends).

-=Cliff>

1Cafe Townsend Demo source http://puremvc.org/pages/demos/AS3/Demo_AS3_Flex_CafeTownsend/srcview/

1Deployment Config Utility source http://svn.puremvc.org/Utility_AS3_Flex_DeploymentConfig/tags/DeploymentConfig_1_0/src-multicore/org/puremvc/as3/multicore/utilities/flex/config/model/
Logged
Pages: [1]
Print