Skip to main content
Inspiring
February 21, 2022
Answered

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

  • February 21, 2022
  • 2 replies
  • 509 views

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?

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    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.

    2 replies

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    February 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.

    Lilybiri
    Legend
    February 22, 2022

    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.

    Astro The Goat
    Inspiring
    February 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

    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.... 

    Lilybiri
    Legend
    February 21, 2022

    @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.