How are custom behaviours in a Symbol triggered from code?

This is my second Hype project so I’m finding my way around. I used ActionScript in Swish and I’m medium familiar with coding, though not JavaScript and HTML in Hype.

I can trigger Custom Behaviours using the dropdowns in the Actions Inspector. But later on I will need to trigger Custom Behaviours conditionally from JavaScript after testing the circumstances of the action. e.g. whether editing is enabled, or in response to a timing event.

In the attached file there are CBs in the LampRed symbol that turn it on and off. The Test1 button uses the dropdowns in the Actions inspector. I would like the Test2 button to have exactly the same effect, but by using JavaScript to call the custom behaviour. (I don’t need to apply conditions in the test.)

Please could someone suggest code to put inside the test2Touched function? (1.4 MB)

To trigger a Custom Behavior using the API

Simply add




to your code.

or if you need to have both mouseup and down call a single script you could try something like

	var mouseEvent = event.type
 hypeDocument.triggerCustomBehaviorNamed( (mouseEvent == 'mousedown' ? 'redLampOn' : 'redLampOff') )

Thanks Mark. So simple when you know it!
It's even listed beneath the code editing screen - I just wasn't searching under Document subheading. Doh!

1 Like