Skip to main content
Inspiring
October 22, 2016
Question

Changing obect states with JS

  • October 22, 2016
  • 3 replies
  • 797 views

I found this function elsewhere on the forum:  

cp.changeState("currentState,"newState");

So if my current state is "Normal" (Default) and the new state is called "Chosen" - I assume I can just add Javascript to a button with the line:

cp.changeState("Normal","Chosen");

 

And this should change the state on button click.

 

But this doesn't seem to work.  Could somebody explain where I'm going wrong?

 

 

 

 

 

    This topic has been closed for replies.

    3 replies

    Stagprime2687219
    Legend
    March 5, 2020

    You may also enjoy this resource with some basic JavaScript examples.

     

    Beginner's Guide to JavaScript 

    Inspiring
    March 5, 2020

    It's actually cp.changeState("objectName","newState");

    Claire_a_bradshaw
    Known Participant
    March 5, 2020

    Thanks for the reply - 

     

    cp.changeState("IR_Alpha","Normal (Default)"); <-- randomly tried this just in case... doesn't work
    cp.changeState("IR_Beta","onState"); <-- works
    cp.changeState("IR_Gamma","normal"); <-- doesn't work
    cp.changeState("IR_Xray","Orange"); <-- works

     

    So I can manipulate the states fine, but as the OP asked, how do you return to the default original state?

     

    thanks!

    Inspiring
    March 5, 2020

    Make it "Normal" (with upper case N; and without the " (Default)" suffix). Should work.

     

    Claire_a_bradshaw
    Known Participant
    March 5, 2020

    I need to do this too - any one solve this?