Issue with moduleReadyEvent CP9 external Javascript
I am trying to create an external script that detects when a captivate SWF ends so the user can choose to move onto the next SWF or quit.
The SWF's are dynamically loaded onto the page using an XML document as a reference and then removed from the DOM using jquery when a new SWF is loaded.
My issue is that the external script works flawlessly. Exactly once. Any videos loaded after the initial video do not activate the script.
var interfaceObj;
var eventEmitterObj;
var i=1;
window.addEventListener("moduleReadyEvent", function evtFunc(evt)
{
console.log(i++);
//evt.Data carries the interface object.
//It is same as window.cpAPIInterface
interfaceObj = evt.Data;
eventEmitterObj = interfaceObj.getEventEmitter();
initializeEventListeners();
//evt.returnValue = true;
return true;
});
function initializeEventListeners()
{
console.log(i++)
//check if window.cpAPIInterface is available
if(interfaceObj)
{
// window.removeEventListener("moduleReadyEvent", function(evt){})
//check if window.cpAPIEventEmitter is available
if(eventEmitterObj)
{
//add a listener to CPAPI_SLIDEENTER event
eventEmitterObj.addEventListener("CPAPI_MOVIESTOP",function endSimFunc(e)
{
console.log("End of Simulation!")
});
}
}
}
I am loading the videos onto the page using a slight variant of the provided code on a CP9 publish.
function linkID(swfObj){
//alert(swfObj.getAttribute("href"));
var swfLink = swfObj.getAttribute("href");
//alert(swfLink);
var strURLFull = window.document.location.toString();
var intTemp = strURLFull.indexOf("?");
var strURLParams = "";
if(intTemp != -1)
{
strURLParams = strURLFull.substring(intTemp + 1, strURLFull.length);
}
//alert("do i run first");
var so = new SWFObject( swfLink, "Captivate", "1300", "874", "10", "#CCCCCC" );
so.addParam("quality", "high");
so.addParam("name", "Captivate");
so.addParam("id", "Captivate");
so.addParam("wmode", "window");
so.addParam("bgcolor","#000000");
so.addParam("seamlesstabbing","false");
so.addParam("menu", "false");
so.addParam("AllowScriptAccess","always");
so.addParam("security", "allowDomain();");
so.addVariable("variable1", "value1");
if(strURLParams !== "")
{
so.addVariable("flashvars",strURLParams);
}
so.setAttribute("redirectUrl", "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
so.write("objectDiv");
return false;
}
Can anyone tell me why the scripts fire only once? I need to be able to detect the end of the published SWF on every video available to the user.
In the JQuery to dynamically load/unload the SWF's I have tried both .remove() and .unload() methods. I am extremely new to Captivate and almost as new to Javascript, so I feel like I am fundamentally misunderstanding how something here is working.
Any help would be extremely appreciated.
