'Retain State' functionality for animated timer

Hi,

Suppose I use animated timer on a slide and while the timer is mid-way, I move to another slide and on coming back to the same slide, animated timer starts running from the same place and does not start from beginning even though I have uncheck ‘retain state’ property for animated timer. I have to add ‘stop timer’ and then ‘start timer’ on slide load as a turn around.

I am using individual animated timer like a progress bar on each slide and it is increasing effort multiple time. Is there any better way to achieve this?

thanks

Hi,

Please put the following code in Project Event (Project Properties > Event) to achieve it better:

if (!prez.oldShowSlide) {
    prez.oldShowSlide = prez.showSlide;
    prez.showSlide = function (data, options) {
        var ret = prez.oldShowSlide(data, options);
        prez.object('Animated Timer_1').stopTimer();
        prez.object('Animated Timer_1').startTimer();
        return ret;
    }
}

Noted that you should rename your timer object name to match the name in the code. For example, with my code, the timer name should be ‘Animated Timer_1’

Regards,

Hey thanks a lot @namnt . Will try this and share feedback.
Appreciate quick reply

Hello @namnt ,

Thank you so much again for sharing the code. I tried it and except for one glitch, everything is working exactly as desired.

When I launch this in HTML5 preview, player toolbar has both Play and Pause button visible and overlapping, probably causing the issue. Only after clicking this button once, it starts.
AP screenshot

Actually am not going to use the player toolbar and have inbuilt buttons to navigate including a progress bar (that’s how this requirement originated). So with this issue and player toolbar hidden by me, I am not able to move forward.

I tried to look for the issue using F12 debug tool but since I am not technical so could not find out. But there was an error highlighted, screenshot below, if this helps.

If you can help resolve this, it would solve everything, rest of the solution seems perfect so far.

thanks

Hi,

It seems the error happens in slides which don’t have the timer. I’ve updated the code for better checking, you should update the code and try again.

if (!prez.oldShowSlide) {
    prez.oldShowSlide = prez.showSlide;
    prez.showSlide = function (data, options) {
        var ret = prez.oldShowSlide(data, options);
        var timerObj = prez.object('Progressbar');
        if (timerObj) {
            timerObj.stopTimer && timerObj.stopTimer();
            timerObj.startTimer && timerObj.startTimer();
        }
        return ret;
    }
}

Regards,

1 Like

Awesome!

It worked perfect. thank you so much for all the help @namnt :smiling_face_with_three_hearts:.

Cheers!

1 Like

Dear @namnt,

I have one more request. I am implementing ‘Show Object’ action on ‘On Load’ event in which I show either of the 2 objects basis condition of ‘apCCVisible’.

Since properties of ‘On Loads’ events cannot be copied across projects, This is humongous task. Could you please help with a java script query which can be applied at project evet level that achieves this above result.

Thanks you so much in advance for all the support.

Best regards

Hi,

Please use the following code:

if (!prez.oldShowSlide) {
    prez.oldShowSlide = prez.showSlide;
    prez.showSlide = function (data, options) {
        var ret = prez.oldShowSlide(data, options);
        var obj1 = prez.object('Shape_1');
        var obj2 = prez.object('Shape_2');
        if (prez.variable('apCCVisible')) {
            obj1 && obj1.show();
            obj2 && obj2.hide();
        }
        else {
            obj1 && obj1.hide();
            obj2 && obj2.show();
        }
        return ret;
    }
}

Regards,

1 Like

Great! Thank you so much.

But I have to apply both the above stopTimer/startTimer and show/hide scripts in the same project. Should I put both the codes one after another as it is or these needs to be merged, as there are many common commands?

Hi,

Yes, you should combine both in one function:

if (!prez.oldShowSlide) {
    prez.oldShowSlide = prez.showSlide;
    prez.showSlide = function (data, options) {
        var ret = prez.oldShowSlide(data, options);
        
        // Timer
        var timerObj = prez.object('Progressbar');
        if (timerObj) {
            timerObj.stopTimer && timerObj.stopTimer();
            timerObj.startTimer && timerObj.startTimer();
        }
        
        // Show/Hide objects
        var obj1 = prez.object('Shape_1');
        var obj2 = prez.object('Shape_2');
        if (prez.variable('apCCVisible')) {
            obj1 && obj1.show();
            obj2 && obj2.hide();
        }
        else {
            obj1 && obj1.hide();
            obj2 && obj2.show();
        }
        return ret;
    }
}

Regards,

1 Like

thank you so much :heart_eyes:

Regards