Copy link to clipboard
Copied
Using Captivate 8.01.
If I place the following code to "Execute JavaScript" for the "On Success" property of a button works fine. But if I try to add it to an Advanced Action, it doesn't take the code unless I remove the For loop. This is just a simple timer loop. Don't understand what's going on here. Any ideas? Thanks.
var inc =0;
var inc1 = window.cpAPIInterface.getVariableValue('countNo'); // Reads Cp variable
inc1 = Number(inc1);
inc1 = inc1 + 1;
// For loop
for (var i = 0; i < 50000000; i++) {
inc = inc + 1;
}
window.cpAPIInterface.setVariableValue('countNo', inc1); // Returns Cp variable
Copy link to clipboard
Copied
It may be working but you'd never know because you are incrementing inc 50 million times,before setting inc1
You should use a setTimeout function instead as it is actual time in milliseconds.
Copy link to clipboard
Copied
Good point. Thanks for the tip. But my original questions was that I was not able to add the code to an Advanced Action (Execute JavaScript). The Script window won't take the code with the For loop in it. If I place the same code to "Execute JavaScript" for the "On Success" property of a button it works just fine, I can place the code with the For loop.
Copy link to clipboard
Copied
Put the code in a function in the HTML and call the function.
Copy link to clipboard
Copied
Thought I would reply, even though a solution has been provided. I had the same problem and a clue re the > sign working (Javascript For Loop not working in Execute Advanced Actions - Execute Javascript?) gave me the solution to using the loops in the Execute JavaScript action. I thought I would share it in case others wanted the solution.
Basically, count backwards.
var total = 0;
for(i=5; i>0; i--){
total+=i;
}
total = 15
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more