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]
Author Topic: proxy, mediator notification problem  (Read 9800 times)

« on: July 31, 2008, 09:36:03 »

hi. My problem is this - I want to create 4 links for my site. Each link contains a background image. So far, I've sent out a notification from the startup command to add a link and passed an object that contains all relevant details (like the image url).

the stage mediator picks up the notification and creates the link object, adds a mediator to the link and adds the link to the stage. it then sends a notification to actually load the image.

a proxy picks up the notification and loads the image. once it's loaded, it send a notification out sending the loaded image.

the link mediator picks up the notification and adds the image to the link object.

whether that's the best way to do things, I don't know, but it's working.

However, when I try to create another link from the startup command using the same method it all goes to hell. I can see why it's doing it because once the image has loaded the proxy just broadcasts a notification which I guess is picked up by all link mediators.

How do I get the correct link mediator to respond to the notification or am I going about this totally the wrong way. I hope this is clear. Any help really appreciated!

« Reply #1 on: August 01, 2008, 04:01:53 »

I got a solution, don't know if it's the best one though. In the proxy that loads the images, I created a dictionary object that stores each loader for the image. so when a notification is sent, a new entry is created in the dictionary and the loader is stored in that. then, when it has loaded, a notification is sent passing the loader.content and the loader.name as a type for the notification.

the mediator that actually adds the links then checks whether it is the correct notification based on the type and if it is, it adds the image to the link. works but don't know if best solution. Any tips, suggestions??  ???
Jr. Member
Posts: 17

View Profile Email
« Reply #2 on: August 01, 2008, 08:20:33 »


You said
a proxy picks up the notification ...

Can you elaborate how you are doing this? I may be able to suggest something after I know how you are doing this.

Global Moderator
Hero Member
Posts: 2871

View Profile WWW Email
« Reply #3 on: August 01, 2008, 11:08:08 »

Use the type parameter of the notification to target the mediator you're interested in. When the mediator invokes the method on the proxy (must be a misstatment in your post, since proxies can't hear notifications), give the proxy your mediator's name. Then when the proxy sends the outbound notification, set that mediator name as the type parameter. In the mediator only act if note.getType() == getMediatorName().


« Reply #4 on: August 01, 2008, 11:39:42 »

ah yes! That makes sense. Thanks a lot. Yeah, my mistake. I meant that I have a LoadAssets command that retrieves the LoadAssets proxy and then just calls the method to load the image. I tried your suggestion and bingo.

I also decided to store the loaded images in a dictionary though since the startup command is creating 4 links which each load a different image. In the load assets proxy just having one loader was causing a problem since it when the notification to load link 2 is sent, the loader information that was processing is reset. By having a dictionary entry each with a loader I could load as many links as I want.

Thanks a lot!
Sr. Member
Posts: 53

View Profile WWW Email
« Reply #5 on: August 05, 2008, 08:14:36 »

To help out with this I've covered in a post too on some best practices for handling registration of multiple instances of a proxy/mediator. Check it out and let me know what you think: http://forums.puremvc.org/index.php?topic=596.0 I'd like to expand it because I think this would help solve a lot of how-to questions.
Pages: [1]