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: Trouble strongly typing custom Notifications  (Read 7059 times)
robmccardle
Newbie
*
Posts: 5


View Profile Email
« on: March 23, 2009, 05:55:51 »


Hi all, first of all this is an amazing library thank you so much Darshan for your excellent work.

I'm studying http://code.google.com/p/fabrication/wiki/ReflexiveNotificationInterests but having trouble strongly typing my notifications as it won't compile. The error I get is:

:
"Incompatible types String and ContextMenuNotification. 'newContextMenuNotification(ContextMenuNotification.ADD_MENU)'"

Here is the Command code that the error happens in:

:
public class BossStartupCommand extends SimpleFabricationCommand {
        registerMediator( new BossMediator( notification.getBody() ) );

// WORKS
// sendNotification( ContextMenuNotification.ADD_MENU );
// DOES NOT WORK
sendNotification( new ContextMenuNotification( ContextMenuNotification.ADD_MENU ) );


}

In my Mediator I have a respondTo function which works fine with INotification as the argument & a vanilla Notification is sent but never gets called when I swap it for my strongly typed version:

:

// OK - public function respondToAddMenu( args : INotification ) : void {
// NEVER CALLED - custom notification for strong typing
public function respondToAddMenu( args : ContextMenuNotification ) : void {
trace("add the menu");
}


My Notification is simple and is extending the Fabrication version, here's the code:

:

package {
import org.puremvc.as3.multicore.utilities.fabrication.patterns.observer.FabricationNotification;

public class ContextMenuNotification extends FabricationNotification
{
public static const ADD_MENU:String = "addMenu";

public function ContextMenuNotification (__evtType : String = "undefined")
{
super( __evtType );
}
}
}


I am using the latest versions of PureMVC Multicore, Pipes & Fabrication with Flash (Not Flex) in FDT. Can anyone point out what I'm doing wrong please? Many thanks :)
Logged
Darshan Sawardekar
Sr. Member
****
Posts: 85


View Profile Email
« Reply #1 on: March 23, 2009, 08:42:09 »

@robmccardle, Thanks for trying Fabrication.

I haven't changed the sendNotification signature in Fabrication from the one in PureMVC. This can't be done in as3 because the override modifier does not allow changing the signature of a method implemented in a parent class. The PureMVC classes implement the sendNotification signature typed to string.

You need to use
:
notifyObservers(new ContextMenuNotification(ContextMenuNotification.ADD_MENU));
Then if you use Reflexive notification interests then with a respondTo like,
:
public function respondToAddMenu(note:ContextMenuNotification):void {

}

you do not need to cast note to ContextMenuNotification. If this were a routed notification then routeNotification supports both string and custom INotification arguments.

peace,
darshan
Logged
robmccardle
Newbie
*
Posts: 5


View Profile Email
« Reply #2 on: March 23, 2009, 10:00:35 »


Magic, I got it working and your explanation makes perfect sense. Cheers for the quick response too!

Kind Regards,

Rob
Logged
Pages: [1]
Print