[SOLVED] Reference to Method's Object, ofEvents

Hey there,

I’ve got a ButtonClass that draws a button and creates events when the button is clicked or hovered over. In the ofApp.cpp file I’ve added a listener for the event, which then calls a method called ‘middleMan’.

Here’s where the question comes in; what would the syntax be if I wanted to change ‘this’ in ofListener to point directly to ‘myvideo’? For example something like…

	ofAddListener(saveButton.clickevent, this, &ofApp::middleMan);


	ofAddListener(saveButton.clickevent, myvideo, &VideoClass::saveImage);

but this doesn’t seem to work.

Essentially, I’d like to cut out the ‘middleMan’.

I don’t want to add the ofAddListener inside the VideoClass if possible.

Here’s the code (intially I put code from all files but it got too messy so I just cut it down to this:

#include “ofApp.h”

void ofApp::setup(){

	// Set bg to dark grey and cap framerate
	ofSetBackgroundColor(20, 20, 20);

	saveButton.setup("Snap!", 30, 30);
	// ********************************************************** //
	// HOW DO I CHANGE "this" to instead refer to the 'myvideo' instance of the VideoClass?
	ofAddListener(saveButton.clickevent, this, &ofApp::middleMan);


void ofApp::middleMan()

void ofApp::update(){


void ofApp::draw(){


I understand that a lot of what I said might have not made sense because I’m trying to explain things as I understand them. I don’t have much programming experience so your help is appreciated :smile:


you just need to add a & before the variable since the ofAddListener function expects a pointer, like:

ofAddListener(saveButton.clickevent, &myvideo, &VideoClass::saveImage);

Thank you Arturo :slight_smile: