PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: sinosoidal on October 14, 2008, 07:49:58



Title: Problems sending notification
Post by: sinosoidal on October 14, 2008, 07:49:58
Hi,

I'm giving my first steps in PureMVC.

I'have already done a login system and now i want to use the framework to manage visual state as well.

For that i have tried to follow the slaker example.

The thing is that after the access is granted, in my access proxie I invoke an AccessGranted notification which will do the following

public class AccessGrantedCommand extends SimpleCommand {
      
      override public function execute (note:INotification) : void {
         mx.controls.Alert.show("im here1");
         
         var applicationMediator:ApplicationMediator;
         
         mx.controls.Alert.show("NOTIFICATION SEN1");
         
         applicationMediator = facade.retrieveMediator("ApplicationMediator") as ApplicationMediator;
         
         mx.controls.Alert.show("NOTIFICATION SEN2");
         
         applicationMediator.sendNotification(ApplicationFacade.MAINDISPLAY_MODE);
         
         mx.controls.Alert.show("NOTIFICATION SEN3");
      }
   }

But no notifitcation is being released. I have placed some alerts to see what is happening and the third alert is not called.

Can anybody help me here?

Thanks,

Nuno


Title: Re: Problems sending notification
Post by: Jason MacDonald on October 14, 2008, 08:13:54
You don't need to retrieve the ApplicationMediator to send a notification, in fact it won't work as you have it. It is the facade that sends notifications. The following will do:
:
public class AccessGrantedCommand extends SimpleCommand {
     
      override public function execute (note:INotification) : void {
         mx.controls.Alert.show("im here1");
         mx.controls.Alert.show("NOTIFICATION SEN1");
         
         facade.sendNotification(ApplicationFacade.MAINDISPLAY_MODE);
      }
   }
I'd also recommend putting your third alert in the listener for MAINDISPLAY_MODE to check if the note is being sent, rather than in the command. What you had only says the command completed, not that the notification sent.


Title: Re: Problems sending notification
Post by: sinosoidal on October 14, 2008, 08:40:04
Hi,

Thanks for the reply.

It is not working. Nothing happens.

I have an Alert in the ApplicationMediator handleNotification method and nothing happens there.

What can be wrong?

This is my ApplicationMediator:

:
public class ApplicationMediator extends Mediator
    {
        public static const NAME:String = 'ApplicationMediator';
       
        public function ApplicationMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );   
        }
       
        override public function onRegister():void
        {
            facade.registerMediator(new MainDisplayMediator(app.mainDisplay));
        }
       
        override public function listNotificationInterests():Array
        {
            return [ApplicationFacade.LOGIN_MODE,
            ApplicationFacade.MAINDISPLAY_MODE]
        }
       
override public function handleNotification(note:INotification):void
{
mx.controls.Alert.show("im here2");

switch (note.getName())
{
case ApplicationFacade.LOGIN_MODE:
app.currentViewSelector = Main.LOGIN;
break;
case ApplicationFacade.MAINDISPLAY_MODE:
app.currentViewSelector = Main.MAINDISPLAY;
break;
           }
       }

        protected function get app():Main
        {
            return viewComponent as Main;
        }

Thanks,

Best regards,

Nuno Santos


Title: Re: Problems sending notification
Post by: sinosoidal on October 14, 2008, 08:50:24
Hi,

Its working!

I found a bug.

Thanks,

Nuno