I have created a simple handle class that notifies on specific events. I have another handle class that listens to these events.
When I create listeners, they all work until I issue the PACK command. The documentation does not mention anything about listener classes breaking when the PACK command is used.
For example, if I define the classes "ToggleButton" and "RespondToToggle" as follows:
classdef ToggleButton < handle properties State = false end events ToggledState end methods function OnStateChange(obj,newState) % Call this method to check for state change
if newState ~= obj.State obj.State = newState; notify(obj,'ToggledState'); % Broadcast notice of event
end end endendclassdef RespondToToggle < handle methods function obj = RespondToToggle(toggle_button_obj) addlistener(toggle_button_obj,'ToggledState',@RespondToToggle.handleEvnt); end end methods (Static) function handleEvnt(src,evtdata) if src.State disp('ToggledState is true') % Respond to true ToggleState here
else disp('ToggledState is false') % Respond to false ToggleState here
end end endend
They work fine if I create the objects and try to generate events:
tb = ToggleButton;rtt = RespondToToggle(tb); tb.OnStateChange(true) ToggledState is truetb.OnStateChange(false) ToggledState is false
However, if I save the objects and reload them, the events no longer trigger.
save myobjs tb rttclear allload myobjstb.OnStateChange(true)
Best Answer