Event handler improvements

  1. Creating custom actions for event handlers would go a long way for making interactive pages. Creating reusable JS is hard since the “Run Javascript” action doesn’t take arguments, and being able to turn a JS function into an action that can be attached to event handlers would seem like an easy way to do this. Converting a function into something that takes a target element, a string, etc. etc. would be extremely useful.

  2. As far as “Run Javascript” as an action goes, the default, uneditable arguments for a JS function take a document and an element, but the list of events doesn’t change target elements. Perhaps this could change?

I did raise this some years ago: Calling Functions & Drag-n-drop tips - #6 by mackavi

I could be wrong but I don’t think event handlers with parameters are on the books. I had hoped that data properties might have made it to the GUI in v3 but not as yet. There is an example on that link how you can do this with a data map instead.

I will say that having built lots of interactive projects over the years, it has turned out that I don’t miss the parameters as much as I thought I would.

There is a quick & easy way to reuse a function if nothing else is possible or time is of the essence - just name your elements accordingly and then use the name in a switch / case in the function to trigger the appropriate response. For example, our hundred square:Interaktiv

All 100 of the number tiles all call the same function on left click. Then using attached properties, the element name or the tiles’ text content the function completes multiple actions.

@arachonteur, you can set data to the target element before the event occurs (e.g. in Scene Activate event), and use this object in the element event handler to get that data. (this object in an event handler is the current target element). Or you can use the element name (this.name) as mackavi’s suggestion.

@mackavi, there are not many users asking for data properties so we’ve not implemented it yet.

Regards

Thanks Toan. It’s not a deal breaker - Saola is already more than capable of building everything I need.