ofEvent dispatching

I’m trying to set up some classes to dispatch and receive events in OF but I keep hitting stumbling points (and errors). I’m sort of just winging it, though this thread had some useful guidance: http://forum.openframeworks.cc/t/ofevent-and-template/3284/0

But I’m kind of stuck again. Just wondering if there is some kind of simple example that shows how to set up a class that sends events with their own arguments extending the ofEventArgs class and having another class that receives them. I couldn’t really find anything in the documentation covering this.

-Aaron

take a look at the advancedEventsExample, it’s sending floats instead of something extending ofEventArgs, but you can use any type for the event and the listener.

post some code if you have any particular problem.

Cool. I’m a little embarrassed that I didn’t even see that example project. Anyway, I tried to follow its design for a test app that sends an event arguments object, but I ran into trouble in a couple places.

I’ve attached the source code. I get an error inside testApp::setup() where I try to use ofAddListener and I get an error inside Sender::fireEvent() where I try to use ofNotifyEvent.

EventTest.zip

this:

  
void receiveEvent(SenderEventArgs args) {  

should be

  
void testApp:receiveEvent(SenderEventArgs & args) {  
  

you’re missing the testApp:: and the parameters to the event listener methods should be passed by reference.

the fireEvent method seems ok to me. can you post the output in case you still have the error

Ok… made the change for the receiveEvent but I’m still getting errors for what seems like both the ofAddListener and ofNotifyEvent parts.

I’m attaching the updated source code and a screenshot of my errors.

EventTest.zip

![](http://forum.openframeworks.cc/uploads/default/640/Screen shot 2010-03-15 at 5.59.25 PM.png)

oh, yes, you’re using a different class for the event declaration (SenderEvent) and then for notifying and listening (SenderEventArgs)

you don’t need one of the two. changing:

ofEvent senderEventOne;

to

ofEvent senderEventOne;

should work

Arturo,

It is working now. Thanks so much for helping me work it out!

-Aaron