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

Best way to change the state of a large number of smart shapes

Explorer ,
Feb 20, 2022 Feb 20, 2022

Copy link to clipboard

Copied

Hi all,

 

I have 30 smart shapes on my page, and I need to change each of them independently to one of three different states, based on a value assigned to variables in java script.

 

Right now my plan is to create 60 conditional tabs, 2 for each shape, with the first tab being:

if myVar1 is equal to A then change state of myshape1 to stateA

 

And the second tab being:

if myVar1 is equal to B then change state of myshape1 to stateB

Else change state of myshape1 to stateC

 

Is there a more efficient way to change the state of a large number of shapes than to use so many conditional tabs? I'd love to have cp.changestate work but when I use it in JS as cp.changestate("myshape1","stateA"); and publish to html5 all subsequent JS in the script window stops executing so I suspect it is not supported by my browser/captivate version somewhere?

Views

163

Translate

Translate

Report

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

correct answers 2 Correct answers

Explorer , Feb 21, 2022 Feb 21, 2022

Hi Tim,

 

First of all you are going to need to have to use three separate if statements, one for each state.  At the moment you test myVar1 for A and change myshape1 to stateA; but your second test uses an if..else whcih means that if myVar1 is not equal to B myshape1 will be changed to stateC.  This will mean that when myVar1 is equal to "A" myshape1 will be set to stateA by the first if statement but will be subseqently changed to stateC by the second if... So just have

 

if myVar1 is equal to A

c

...

Votes

Translate

Translate
People's Champ , Feb 21, 2022 Feb 21, 2022

If you execute this JS, with the initial value of myVar1 is equal to 0:

if (myVar1 != 0)

{

cp.changeState("myshape1", "state"+myVar1)

}

else

{

cp.changeState("myshape1", "Normal")

}

 

It will change the state to whatever the value of myVar1 is by concatonating "state" and the value of myVar1. Else it will go to the normal statee if the value is 0.

Votes

Translate

Translate
Explorer ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Hi Tim,

 

First of all you are going to need to have to use three separate if statements, one for each state.  At the moment you test myVar1 for A and change myshape1 to stateA; but your second test uses an if..else whcih means that if myVar1 is not equal to B myshape1 will be changed to stateC.  This will mean that when myVar1 is equal to "A" myshape1 will be set to stateA by the first if statement but will be subseqently changed to stateC by the second if... So just have

 

if myVar1 is equal to A

change msyshape1 to stateA

if myVar1 is equal to B

change msyshape1 to stateB

if myVar1 is equal to C

change msyshape1 to stateC

 

You can then use a Shared Action so that you only need to write the code once and you can supply the Shared Action and  with the different names of each of the 30 "Shape" objects you have. 

 

If the JavaScript isn't working then it's probably a fault in the code - remember that JavaScript is "case sensitive" so  cp.changeState() is correct cp.changestate() isn't 🙂

 

Hope this helps.... 

Votes

Translate

Translate

Report

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

@Astro The Goat  Sorry, but a Shared action would need a lot of parameters, not only the name of the multistate object, but also the three state names which is very annoying. I agree about needing a 3-decision action, skipping the ELSE parts. For sure, having 30 instances of a shared action is to be preferred over one advanced action with a mutlitude of decisions. If it would save time, having to apply that shared action to 30 shapes, each time entering 4 parameters which was the goal of this question, is to be doubted. Duplication of decisions is very easy in Captivate.

http://blog.lilybiri.com/tip-3-show-slash-hide-or-multistate-object-advanced-slash-shared-actions

That blog tries to explain why a Show/Hide scenario has advantages over state changes in a shared action.

Votes

Translate

Translate

Report

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

OMG it was the capitalisation of changestate, thanks! This is the best solution, as @TLCMediaDesign said below I can construct the shape names and be much more efficient.

 

If I had gone with the other suggestion of a shared action though, is there a way I could have 'called' the shared action from inside my main advanced action? Right now it is set up as an advanced action, which runs javascript to change some variables that are then used by the advanced action in later conditional tabs. I'd love it if I could run another action at the end of that but haven't seen that this is possible.

Votes

Translate

Translate

Report

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 ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

LATEST

@Tim_JF You cannot call an action from another action, except when you are using CpExtra (InfoSemantics - Australia).

Within some limits you can use JS within a shared action. However, as I pointed out before, I would not go with a shared action in this case myself. TLCMediaDesign without any doubt offers you the most efficient solution, which is impossible with a shared or advanced action due to the lack of the concatenation feature. For that reason I have marked his solution - being the most efficient - also as correct answer. This is more for other users looking for the most efficient way to solve this situation. It is one of the tasks I need to do as a moderator.

Votes

Translate

Translate

Report

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

If you execute this JS, with the initial value of myVar1 is equal to 0:

if (myVar1 != 0)

{

cp.changeState("myshape1", "state"+myVar1)

}

else

{

cp.changeState("myshape1", "Normal")

}

 

It will change the state to whatever the value of myVar1 is by concatonating "state" and the value of myVar1. Else it will go to the normal statee if the value is 0.

Votes

Translate

Translate

Report

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 ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

Thanks, David. You may understand now why I am begging since about 10 years to have concatenation available in advanced/shared actions. Too bad.... no one supported me. Especially with applying states - as you expertly pointed out -  this is THE way to go.

Votes

Translate

Translate

Report

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