Could I get an example or two of how to use the ‘custom method’ in component scripting?
I can’t seem to grasp how to utilize it.
My goal is to be able to drag-n-drop tags from a tag browser tree into a standard table component.
The standard table component doesn’t have a ‘onTagsDropped’ extention function like some other compoennts do.
So I want to add that functionality - possibly through a custom method?
Unfortunately, no, that won’t work. Custom methods are conveniences for consolidating code for a component, with a self object available for the code, but nothing in Ignition will automatically call them. To implement onTagsDropped for a component that doesn’t natively support it would require a bunch of Java Swing hackery, if doable at all.
Probably the most common use of custom methods is to get access to self in runScript bindings. I hardly ever use those, as I can do better with my objectScript() expresssion function (part of the free Simulation Aids modules), without needing custom methods.
One big advantage is separating logic from event handling - ie, if you want a component to do the same thing on key press that it does on right click (for a contrived example) you can just have each event handler call the same custom method, to avoid duplicating logic.
@PGriffith Interesting Would you mind sharing the code for your ‘addListener()’ custom method?
Also to make it work you need the ‘initialize()’ extension function right?