ActivePresenter Saola Animate Pricing Download

Navigat Timeline With JS

Hello.
I need to be able to target the timeline with JS from a button. I am trying gotoAndStop(3); but this doesn’t seem to be working?
Specifically I have this old Hippani random generating code I am tryng to translate to Saola Animate:

var R=Math.floor((Math.random()*6)+1);
if(R==1){

GotoAndStop(0);
}
if(R==2){

GotoAndStop(1);

}
if(R==3){

GotoAndStop(2);
}

Many thanks
Deek

Hi Deek,

There’s no gotoAndStop function and frame concept in Saola Animate.

In Saola Animate, you need to use doc.getTimeline('Timeline name') to get the timeline.
After that, use play, pause methods of the timeline to control it.

You can enable Show API option in the script editor to see APIs that Saola Animate supports:

We also provide many tutorials that you can take a look at:

In case JavaScript is not required, you can use Timeline actions:

image

Regards

Hi Toan Le.
Thank you for the example. It helps a lot. I am just worried that “Pause” will only pause a “Playing” timeline? Specifically I need the command to “jump” to a specific timeframe without it playing from frame 0 and just “Stop” there to display an image?

Deek

Hi Deek,

Pause a timeline at a time or label will make the timeline jumps to and pause at that time/label.
So it’ll work as expected.

Regards

Hey ToanLS.
I decided to use scenes instead of frames as a work around and found this code here on the forum BUT it is not jumping to the sceneTime 2 (2 seconds) in Scene_2 for some reason? It is just going to Scene_2 and playing from frame 0.

function elementEventHandler(doc, e) {

doc.showScene(‘Scene_2’, {sceneTime: ‘2’});

}

Cheers
Deek

sceneTime: '2' option will go to the label ‘2’ in the timeline if any.
To go to 2 seconds, you can use sceneTime: 2000 (Saola Animate use milliseconds).

Regards

ToanLS You guys are amazing thank you for your tolerance.
I managed to get it to work with Labels:

function elementEventHandler(doc, e) {

doc.showScene('Scene_1', {sceneTime: 'Test'});

}

But this code did not work???

var timeline=doc.getTimeline(Timeline_1');
timeline.pause(3000);

EDIT: Oh and thanks for the help I also got this working (“Timeline_1”);
Cheers
Deek

Timeline name is a string/text, and any text should be in 'single quotes' or "double quotes".
It’s likely that you missed the opening quote before Timeline_1.

Regards

Ahh…yes I see . Thanks again ToanLS.
I am nearly there…just getting a final parsing error with this code I am trying to implement from Hippani for a random Image Generator: I don’t know why it is not working?

function elementEventHandler(doc, e) {

var R=Math.floor((Math.random()*6)+1);

if(R==1){

doc.showScene('Scene_1', {sceneTime: 'One'});

}

if(R==2){

doc.showScene('Scene_1', {sceneTime: 'Two'});

}

if(R==3){

doc.showScene('Scene_1', {sceneTime: 'Three'});

}

if(R==4){

doc.showScene('Scene_1', {sceneTime: 'four'});

}

if(R==5){

doc.showScene('Scene_1', {sceneTime: 'Five'});

}

if(R==6){

doc.showScene('Scene_1', {sceneTime: 'Six'});

}

The apostrophes you’re using to wrap strings are wrong. This can happen when copying and pasting - especially from different OS’s like Mac.

Use the editor’s find and replace to switch to the correct character. The strings will be a different colour if correct.

EDIT:
it’s all good. It’s working :slight_smile: Just needed another curly bracket at the end.
Thank you all for the responses. You all helped and I am extremely thankfull
Cheers
Deek

Hi Deek,

You can use code formatting so that quotation marks are not converted when posting code in this community.

For finding JavaScript syntax error in Saola Animate, you can press F12 when previewing in the browser to see more information in the browser console.

Regards

Thanks again TaonLS
Very handy to know for a beginner :wink:

EDIT: I also found a couple of online JS Checkers which alerted me to the error as well!

Cheers
Deek

1 Like