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: Dom Level 3 in Commands - listen to components that use Flash event model?  (Read 10571 times)
pebanfield
Full Member
***
Posts: 33


View Profile Email
« on: January 01, 2009, 09:11:28 »

Hi -

Not exactly sure if this is the problem. It's only a hunch at this point, but here are the clues and context.

I need to use a third party component in my application and I have no access to the source code. The component makes requests to an ad server and returns xml. The basic API for the component is to instantiate the component, call methods on it and listen for callbacks. The listeners are created IEventDispatcher style so I'm assuming the component to be a Sprite or some kind of displayObject.

I am currently refactoring my app from a basic Sprite based design over to Pure MVC. In the earlier version I instantiated the ad component object and did not need to add it to the stage to handle the xml load event. However, it was hosted in a Sprite that existed within the Flash dom. It works fine this way.

In my new Pure MVC based version I am trying to house this logic in a command called LoadAdCommand. This command listens for the ad response and I was intending to either update a model object via proxy or simply send a notification containing the ad xml back to the mediator to execute further ad display logic.

At present the xml loaded event is not firing in my command, however I can see the response coming back correctly in Firebug.

Anyone have any ideas? Thanks!

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



View Profile WWW Email
« Reply #1 on: January 01, 2009, 09:35:37 »

You want to use AsyncCommand for this, probably.

-=Cliff>
Logged
pebanfield
Full Member
***
Posts: 33


View Profile Email
« Reply #2 on: January 01, 2009, 10:36:52 »

Hmm. Well the event handler is not executing so I don't see how this will solve my problem but thanks. Interestingly, the component dispatches another custom event that appears to forward Loader events (e.g. HttpStatusEvent) and this is firing. But the plain Event type is not firing.

I think this has to do with the Flash DOM and bubbling display events somehow. This is of course not the concern of Pure MVC so I'll have to find some kind of work around. Maybe best to just dump the component since I can write my own code based on the request/response headers. Thanks.

Peter
Logged
pebanfield
Full Member
***
Posts: 33


View Profile Email
« Reply #3 on: January 01, 2009, 11:05:03 »

Oh hay wait - suppose the AsyncCommand would be good since I can remove listeners in onComplete. Any other reason? Thanks.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: January 02, 2009, 11:33:46 »

I thought it could be a timing issue. Can't help the component not firing the event, true.

-=Cliff> 
Logged
pebanfield
Full Member
***
Posts: 33


View Profile Email
« Reply #5 on: January 02, 2009, 05:23:31 »

Doh! Turns out that while a response was coming back from the ad server - it was lacking some specific data and so the component was dispatching the event. So there is now no problem with listening for a generic event from the scope of a non display object.

However, my actual problem did arise from a design issue from an earlier thread. It turns out that I was overwriting some configuration values required to make the ad call properly. This was because I am using the same proxy for multiple commands and was forgetting to use facade.retrieveProxy for the second rather than instantiating.

It seems to me that a singleton proxy or model object would help out here. What are your thoughts on this? Any problems with this?

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



View Profile WWW Email
« Reply #6 on: January 03, 2009, 08:16:54 »

You can certainly create a singleton if you'd like and still preserve the normal PureMVC methodology. Rather than doing the Singleton in the normal way, have its getInstance method check *not* for a static class variable but instead, for the return of Facade.getInstance().retrieveProxy(). If not null, simply return the retrieved Proxy, else construct a new instance and register it with Facade.getInstance().registerProxy.

A self-registering PureMVC singleton Proxy that can be retrieved in the normal way.
 
Note:of course getInstance is static and so doesn't have access to the concrete facade as an instance does. Use the framework Facade class not your concrete ApplicationFacade, which you'll just be making IFacade calls on anyway. This keeps the Proxy free of reference to your concrete class. It extends Facade and will have been stored as the singleton instance of Facade by this time anyway. This keeps the Proxy portable since it only references the framework class. 

-=Cliff> 
Logged
pebanfield
Full Member
***
Posts: 33


View Profile Email
« Reply #7 on: January 11, 2009, 01:28:32 »

Hay this sounds great. I'm going to try it out. Thanks and happy new year!

Peter
Logged
Pages: [1]
Print