Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How change state smartshape via javascript?

Community Beginner ,
Oct 02, 2016 Oct 02, 2016

Hello everyone!

i am using Captivate 9

How change state or properties (background color, font, size, ets.) SmartShape via javascript?

Thank you!

3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 03, 2016 Oct 03, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 11, 2016 Oct 11, 2016

Unfortunately it doesn't work.

How do I apply a function cp.changeState("currentState,"newState"); to a specific SmartShape?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 11, 2016 Oct 11, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 11, 2016 Oct 11, 2016

Thank you so much! It's work!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 22, 2016 Oct 22, 2016

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2016 Oct 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2016 Oct 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2016 Oct 23, 2016

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.

1 action = 5 Toggle Buttons - Captivate blog

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2016 Oct 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2016 Oct 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2016 Oct 23, 2016

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");  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 30, 2016 Oct 30, 2016

try cp.changeState("SmartShape_1","newState");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 30, 2016 Oct 30, 2016

Aha!  That works.  Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2017 Jul 12, 2017

I found your suggestion of cp.changeState very useful. Where did you find that? Is there a list somewhere?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2017 Oct 17, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2019 Jul 08, 2019
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources