Listener callback casts custom event data back to event.eventData?

I have a simple subclass of event.EventData to pass data to listeners:
classdef (ConstructOnLoad) tuningEventData < event.EventData
properties
path
value
end
methods
function obj = tuningEventData(path, value)
obj.path = path;
obj.value = value;
end
end
end
I trigger an event, passing a tuningEventData object:
notify(obj, 'tuningChange', tuningEventData(path, val));
Now I have one listener receiving this and triggering yet another event in its callback method, which I'd like to pass on the same tuningEventData object:
function handleTuningChange(obj, src, data)
notify(obj, 'tuningChange', data);
end
But listeners to this new event do not receive the tuningEventData object. They receive an EventData object instead which obviously doesn't have the path and value properties.
The only way to pass on a tuningEventData object seems to be creating a new object in the first listener's callback:
function handleTuningChange(obj, src, data)
notify(obj, 'tuningChange', tuningEventData(data.path, data.value));
end
Why can't I just send the data object straight on? Is my tuningEventData class missing something?

Answers (1)

Change obj.path and obj.value to data.path and data.value

Categories

Products

Release

R2017a

Asked:

on 9 Oct 2018

Answered:

on 10 Jan 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!