Javascript using event in another event

How do I use an event in another event in Saola with JS?

Can I use the timeline-update event in the activation-of-a-scene event? So when the timeline has ended or has reached a certain point in time I want to trigger a function in the activation-of-a-scene event. I think an easy way would be to use the event timeline-update?
How to do this?

Hi Klaas,

To trigger an action at a certain point in timeline, you should use timeline triggers https://atomisystems.com/html5-animation/using-timeline-triggers/

Regards

Hi Toan Le,

Thanks for responding,

Yes I am aware of this and have a trigger inside of the timeline-update event that fires when the timeline duration == this.value. My ‘issue’ is that I have quite some code in my ‘onSceneActivated’ event that I want to re-use but this code will work only in this event. It creates and links to quite some elements and in another eventhandler I would have to re-do all these code again this way with possible mistakes and so on. Therefore it could be very handy to make a simple call to another event handler and make use of the existing code and variables.

Is it even possible to call other events for this? Or maybe this is not advisable for bigger projects for some reason?

Hi Klaas,

You can assign your variables and functions to doc object in Scene Activate event and call them in a timeline trigger, e.g:

// in scene activate
doc.myFunc = function(param) {
  // function body
};

// in timeline trigger
if (doc.myFunc)
  doc.myFunc(param);

You can also add Normal Functions as common functions in Functions pane and call them in any events: https://atomisystems.com/html5-animation/creating-calling-javascript-functions/

In case you want to trigger at a time that can only be specified when the scene is activated, you can use the following code:

var mainTimeline = doc.getTimeline();
var time; // calculate the trigger time here
mainTimeline.addTimingEvent(new AtomiSaola.TimingEvent([time, [function(doc, event) {
  // add code for your trigger here
}]]));

However, TimingEvent constructor is not a public function, so it may not work in future updates.

Regards

HI ToanLS,

Thanks a lot for this help. This will bring me further in my project.

Regards,
Klaas