Copy link to clipboard
Copied
Hi--
Just trying to save the user's slide number during a movie and reload it if the user leaves and returns. My CP files run in an iframe on a parent page with some JS functions on the parent that communicates with our database.
So, when the page loads, I load the user's last viewed slide number and as the user changes changes slides, I save it with some calls to the JavaScript. This is the code on the first slide with On Enter:
var jump=parent.getSlide();
if (jump>0) {
window.cpAPIInterface.setVariableValue('cpCmndGotoSlide', jump);
}
window.cpAPIEventEmitter.addEventListener("CPAPI_SLIDEENTER",function() {
parent.setSlide(cpInfoCurrentSlide);
});
This works perfectly when publishing as HTML, but when publishing as SWF, only the first function gets called. I can change the frame number in my database and my file will read and jump to it when loading. However, when publishing as SWF, the event listener doesn't seem to fire. I've even removed the listener and just added:
parent.setSlide(cpInfoCurrentSlide);
to the script and it does nothing. I've even tried cpInfoCurrentFrame and nothing.
Am I missing something or does this just not work with SWF? I'm using CP 9 and using Internal Server Reporting.
Any help is greatly appreciated.
Thank you!
Copy link to clipboard
Copied
More than likely the cpAPIInterface doesn't exit yet when you are trying to add the listener.
You should first add a listener for the moduleReadyEvent
window.addEventListener("noduleReadyEvent", function()
{
//YOUR LISTENER HERE
}
Copy link to clipboard
Copied
Thank you so much for the reply. Unfortunately, it's still not working. Here is my code again for reference:
var jump=parent.getSlide();
if (jump>0) {
window.cpAPIInterface.setVariableValue('cpCmndGotoSlide', jump);
}
window.addEventListener("moduleReadyEvent", function() {
alert('ready');
window.cpAPIEventEmitter.addEventListener("CPSlideEnterEvent",function() {
parent.setSlide(cpInfoCurrentSlide);
});
});
The first JS call works fine. I'm not even seeing the alert message in the listener. What else could be happening?
EDIT:
Just for fun, I distilled the code to the bare minimum:
alert(cpInfoCurrentSlide);
Nothing still. This is set to run On Enter and it's on the first 3 slides.
Does cpInfoCurrentSlide not work with SWF?
EDIT 2:
Just tried this in the trial version of CP 2017 and it still doesn't work. Back to the drawing board...
Copy link to clipboard
Copied
You'll need to use window.cpAPIInterface.getVariableValue("cpInfoCurrentSlide")
Copy link to clipboard
Copied
Success! Thank you.
However, the event listener still isn't firing.