Captivate 7: get and set variables only for javascript html5 output… HELP!
Copy link to clipboard
Copied
Unfortunately it looks like that the only resource (a pay one) in the whole www to know the necessary code to get the values from captivate's variables and set variables' values back through javascript commands for HTML5 output (only interest) is the "JavaScript Video Series for Adobe Captivate 7" from CaptivateDev.com… which, I can't afford… I've basic knowleg in js, and please I'd like a little help with that, OR just fix the following syntax please, I'm stuck with this project cuz doesn't want to run in html5:
I've the following variables in captivate
Associated with TEBs:
PROM
AABS
ABIO
AQUIM
AVERB
SBIO
SQUIM
SVERB
Associated with a text labels ($$variable$$):
vIIA
vIA
And I need to calculate the following operations in javascript:
var IIA = ((((AABS*3)+((ABIO*3)-(25-SBIO-ABIO))+((AQUIM*3)-(25-SQUIM-AQUIM))+((AVERB*3)-(25-SVERB-AVERB)))*20)/300)
var IA = ((((PROM*(4*(PROM-10)))+(IIA*(100-(4*(PROM-10))))))/100)
(Imagine doing that with the advance action assistant)
Finally these operations display in text labels which are: $$vIIA$$ and $$vIA$$
…Thanks in advance
Copy link to clipboard
Copied
Where is your JS syntax? And it is perfectly possible with Advanced actions, maybe seems cumbersome but since you don't want to spend money on Jim's very valuable course.
Copy link to clipboard
Copied
I tried to be clear, I didn't say "I don't want to spend money" I just said "I can't afford it" I would've done is were possible in this moment, but anyways it's sad there is not any free tutorial about… I didn't post the sintax because i've trying in many differents ways and none result, so I thought it was better to expose the problem in this forum without having the wrong sintax crowding the post.
Copy link to clipboard
Copied
You'll need to get the variable values with:
cp.vm.getVariableValue(varName);
You can also access them in the window object:
window.varName
Then set the value with:
cp.vm.setVariableValue('varName', varValue);
Copy link to clipboard
Copied
I'm missing something in the script (that execute a button), there is my code:
var calc = function (){
var PROM = cp.vm.getVariableValue(uProm);
var AABS = cp.vm.getVariableValue(uAabs);
var ABIO = cp.vm.getVariableValue(uAbio);
var AQUIM = cp.vm.getVariableValue(uAquim);
var AVERB = cp.vm.getVariableValue(uAverb);
var SBIO = cp.vm.getVariableValue(uSbio);
var SQUIM = cp.vm.getVariableValue(uSquim);
var SVERB = cp.vm.getVariableValue(uSverb);
var IIA = ((((AABS*3)+((ABIO*3)-(25-SBIO-ABIO))+((AQUIM*3)-(25-SQUIM-AQUIM))+((AVERB*3)-(25-SVERB-AVERB)))*20)/300);
var IA = ((((PROM*(4*(PROM-10)))+(IIA*(100-(4*(PROM-10))))))/100);
cp.vm.setVariableValue('IIA', vIIA.toFixed(3));
cp.vm.setVariableValue('IA', vIA.toFixed(3));
};
calc();
The labels $$vIIA$$ and $$vIA$$ don't display the value yet ¿what I've missed here? …by the way the variables associated with TEBs are those who have the prefix "u" and not those I commented in first place (uppercase variables)
Copy link to clipboard
Copied
In the lines that do the calculations the variables should be:
var vIIA and var vIA
You are setting the value of IIA and IA to a variable that has never been defined, as in:
cp.vm.setVariableValue('IIA', vIIA.toFixed(3));
Copy link to clipboard
Copied
The variables vIA and vIIA has been defined in the project variables, and the 2 text labels display them $$vIA$$ and $$vIIA$$ so if I set the sintax as you told me, it will have not any sense the parameters of the last two lines:
var vIIA = ((((AABS*3)+((ABIO*3)-(25-SBIO-ABIO))+((AQUIM*3)-(25-SQUIM-AQUIM))+((AVERB*3)-(25-SVERB-AVERB)))*20)/300);
var vIA = ((((PROM*(4*(PROM-10)))+(IIA*(100-(4*(PROM-10))))))/100);
cp.vm.setVariableValue('vIIA', vIIA.toFixed(3));
cp.vm.setVariableValue('vIA', vIA.toFixed(3));
Copy link to clipboard
Copied
The syntax is setVariableValue(cpVariable, value)
you were trying to set the value using an undefined variable.
Do not change the Captivate variable, it should be:
cp.vm.setVariableValue('IIA', vIIA.toFixed(3));
cp.vm.setVariableValue('IA', vIA.toFixed(3));
Copy link to clipboard
Copied
Thanks for the previous posts but I still can't figure this sh*t out.
I have:
- a variable named "text" with value hello.
- 1 slide with a textbox with variable $$text$$ in it
- Javascript: cp.vm.setVariableValue('text', 'bye');
And nothing happens.
Test 2:
I have:
- a variable named "text" with value hello.
- 1 slide with a textbox with variable $$text$$ in it
- Javascript: var test = cp.vm.getVariableValue(text); alert(test);
And it alerts an empty alert box
Thanks in advance!
Copy link to clipboard
Copied
What version of Captivate and what type of output, swf or HTML5 or both?
Copy link to clipboard
Copied
Hi thanks for the fast response,
I use Captivate 7 and HTML5
and i use the browser preview.
Sorry for not specifying.
Copy link to clipboard
Copied
Just use:
window.yourVaraibleName = "someValue";
In html5 all of the variables are in the window object
Copy link to clipboard
Copied
Thank you so much for explaining this, thought I would never get this to work!!!!!
Is there a way I can do something like this:
var number = window.YourVaraibleName;
number + 5;
I tryd to add:
ParseInt(number);
But no result
Copy link to clipboard
Copied
Sorry I'm a javascript noob
It's:
number = number + 5;
Thanks for the help!

