Copy link to clipboard
Copied
Hello everyone!
i am using Captivate 9
How change state or properties (background color, font, size, ets.) SmartShape via javascript?
Thank you!
Copy link to clipboard
Copied
My suggestion would be to create the states in CP, then if you need to change it using JavaScript use:
cp.changeState("currentState,"newState");
It can be quite tricky to manipulate the canvas elements without knowing exactly how it is constructed.
Copy link to clipboard
Copied
Unfortunately it doesn't work.
How do I apply a function cp.changeState("currentState,"newState"); to a specific SmartShape?
Copy link to clipboard
Copied
You need to know the names of the states, currentState and newState are just placeholders to show you what goes where in the arguments.
So the first parameter is the name of the element state that is currently active, the second parameter is the name of the state you want to show.
Copy link to clipboard
Copied
Thank you so much! It's work!
Copy link to clipboard
Copied
Hi TLC,
I have a button called SmartShape_1
and I've added this JS code to the button on-click:
cp.changeState("Normal","newState");
But there's no change of state. Could you please explain my error?
Copy link to clipboard
Copied
Sorry to pop in, beause your question is addressed to TLCMediaDesign. That command in JS is the alternative for the advanced actions command 'Change state of.....'. I wonder if I have to link this with your other thread? The state has to exist in Captivate before you can use the AA command or the JS command. I don't believe it is possible to ​create​ a state with JS.
Copy link to clipboard
Copied
I'm glad to hear input from anyone on this issue. I created the state in captivate in the regular mode. It's the 4th state - after normal rollover and down.. I just want to make the object alternate states through javascript.
In fact, I wouldn't feel the need to do this at all if the command "Go to next state" were included in Advanced Actions, but since it's not - it's only in simple action - then I'd I'be forced to choose it instead of executing javascript. And I need to use javascript for other types of commands linking to a spreadsheet.
Copy link to clipboard
Copied
If you have only one custom state, why would you need Go to Next State? Contrary to most imes, variables and actions in Captivate you can label that custom state with the same name for all your buttons. InBuilt states are diiferent as I tried already to explain in the other thread. If you want always to show the 'Done' state (name which I use for the 4th custom state), you can use one command in all your advanced actions that will be 'Change State of Bt_x to Done'. I also would like to have Go to Next State in the AA dialog box, but in this particular case you don't need it at all, since you can only interchange the Normal state with a Custom state, not the Rollover or Down states. Again: confusing, because those InBuilt states seem to be treated the same as the other states, but they are different, they are part of the button style.
If you have time, this article shows a shared action that is used for 5 different buttons, where you'll see how the Normal and a Custom state are used.
Copy link to clipboard
Copied
But I'd need to choose the individual name of each button in separate advanced actions, right? I can't just choose "current button".
So with dozens of buttons, it seems i'd have to create dozens of different advanced actions - all using the same javascript, but a different "change state" command.
Copy link to clipboard
Copied
That is the reason I posted that link to show how shared actions make this easy. Moreover they are in the Library as assets, which make managing much easier. All depends on your JS skills, if you can do everything with one function that you call from Captivate, it could be quicker. I prefer shared actions, but am sure others will prefer JS.
Copy link to clipboard
Copied
Hi Lilybiri,
Thanks for the link. The shared action would indeed be faster to implement than other alternatives, but in my case a JS command would be ideal. Has anyone else been able to use a code like this to change states on-click?
cp.changeState("Normal","newState");
Copy link to clipboard
Copied
try cp.changeState("SmartShape_1","newState");
Copy link to clipboard
Copied
Aha! That works. Thank you!
Copy link to clipboard
Copied
I found your suggestion of cp.changeState very useful. Where did you find that? Is there a list somewhere?
Copy link to clipboard
Copied
The official list is here, but it is incomplete: Learn about the Common JavaScript interface for Adobe Captivate
The 2 undocumented functions I used the most are cp.changeState and cp.SubmitInteractions. I strongly recommend Googling those.
Note that cp.SubmitInteractions does not seem to work inside of Advanced Actions (at least not when I try it in Adobe Captivate 2017), which is sad because it would allow for an easy way to call an Advanced Action from another Advanced Action. The add-on called CpExtra seems to be the only way to do that, as things stand right now.
Copy link to clipboard
Copied
I'm using Captivate 2019.
FYI at least in the current version, the first argument of this function is the object name, not the current state.