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?
Copy link to clipboard
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.
Hope this helps....
@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.
That blog tries to explain why a Show/Hide scenario has advantages over state changes in a shared action.
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.
@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.
Copy link to clipboard
If you execute this JS, with the initial value of myVar1 is equal to 0:
if (myVar1 != 0)
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.
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.