Skip to main content
Known Participant
November 14, 2016
Question

How to switch the state of an object in javascript?

  • November 14, 2016
  • 4 replies
  • 4363 views

Hello guys,

I have a big problem with my new HTML5 projects, i used always the SWF publish in the past... everything in my captivate is now based on HTML5 and javascript, and i do not use the advanced actions anymore... except of if i wanna switch the state of an object i have to do a mix of javascript and advanced action... so i am still searching for a java-command in which switches the state of an object... can anybody help?

This topic has been closed for replies.

4 replies

GilMichelini
Inspiring
December 6, 2018

This worked for me once I created duplicates of the built in states

function stateChanger(btnName) {

var tTemp = window.cpAPIInterface.getVariableValue("play_pause_status");

if (tTemp == 1) {

cp.changeState(btnName, "Play");

} else {

cp.changeState(btnName, "Pause");

}

}

Lilybiri
Brainiac
December 6, 2018

Lot more complicated than a simple condition action. Why make it simple when it can be done in a more complicated way?

Participating Frequently
March 17, 2017

First,  the format of cp.changeState is not

 cp.changeState("oldstate","newstate") 

it is:

 cp.changeState("shapeID","newstate") 

Second, you need to set up and use states that are not "system" states.   Captivate monitors the system states and changes them at uncontrolled times.   Once you create a custom state,  captivate tends to leave it alone.  This can be seen in the javascript console.  if you change a button to "Down" state using javascript, if you mouse over it,  it returns immediately to Normal.

RonLin
Known Participant
April 18, 2018

I tried this changeState("shapeID", "statename") but it doesn't work in CP9.0.1.320

RonLin
Known Participant
April 18, 2018

OK it only works via HTML5...

TLCMediaDesign
Inspiring
November 15, 2016

I've never done what you are doing, but if the state names are not different I can't imagine CP really knows what you are trying to do. So name them all differently and if you want to change the states of all four buttons, use cp.changeState four times.

Lilybiri
Brainiac
November 15, 2016

David, could the issue be due to the fact that Normal, Rollover and Down are InBuilt states, not custom states?

TLCMediaDesign
Inspiring
November 15, 2016

Could be Lieve, I've never found a reason to try and control the state of a smartshape button.

TLCMediaDesign
Inspiring
November 14, 2016

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

You need to know the names of the states.

Known Participant
November 15, 2016

but i need know give with the name of the object, dont i? because when i duplicate the object then the names of the states are the same... and each object has the state "normal"

TLCMediaDesign
Inspiring
November 15, 2016

I don't understand. Are these button? Can you not change the names of the states?