I think i have stupid problem… but i don’t find the solution. I’m trying ofAddListener, i write this code:
ofAddListener(ofEvent.mouseReleased, this, &testApp::myCustomMouseReleased);
and i have this 2 error:
- Cannot refer to class template ‘ofEvent’ without a template argument list
- Missing template arguments before ‘.’ token
What is the problem?
Hi, I think your code should be
ofAddListener(ofEvents.mouseReleased, this, &testApp::myCustomMouseReleased);
ofEvent is the basic event class, while ofEvents is a collection of predefined events.
Thanks for explanation of my stupid question.
No worries… ofEvents also had me confused in the beginning!
Another question… i think i will have many questions, i’m studyng these slides http://www.roxlu.com/blog/entry/145/openframeworks-007-presentations/page/ and this is the unique place where i can find people and ask!
So… i create my event class, only with file header:
After in my “testApp.h” i write:
void myCustomEventListener(myTestEvent& args);
And in “testApp.cpp” in setup:
ofAddListener(myCustomEventDispatcher, this, &testApp::myCustomEventListener);
If it’s all right, now i have a listener. I also create a function “myCustomEventListener” with a simply output.
But now… how can i dispatch my event? I see ofNotifyEvent, but doesn’t work and i don’t know how to use it.
You have to instantiate an ofEvent with your event as the templated parameter and then fire this event.
I didn’t test this code, but it should go something like this:
//create event and listener
ofAddListener(theEvent, this, &testApp::myCustomEventListener);
static myTestEvent event("evt");
It works! Thanks again.
I don’t understand why you use static. I know what is “static” but why do you think is better to use here?
Anyway, i have found one new thing that i didn’t know before. If i write:
myTestEvent(string someData, int number):cont(number), data(someData)
the values of someData and number go direct into data and cont. This is new for me, you know the name of this technique?
You’re just setting the values of those variables in the constructor. Underdoeg is right about dispatching the events, you just need to use ofNotifyEvent(). There’s a more advanced example in the of download advancedEventsExample, that might be helpful.
Yes, i have seen the example but it’s look little different from the slides. Anyway, now i have understand some more, so i come back to try again new stuff.