Skip to main content
Known Participant
Nov 14, 2016 5:49 PM UTC
Question

How to switch the state of an object in javascript?

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 is closed to new replies. Start a new post to keep the conversation going.

16 replies

GilMichelini
Inspiring
Dec 6, 2018 9:57 PM UTC

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");

}

}

Translate
Lilybiri
Legend
Dec 6, 2018 10:48 PM UTC

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

Translate
Participating Frequently
Mar 17, 2017 4:43 PM UTC

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.

Translate
RonLin
Known Participant
Apr 18, 2018 1:11 PM UTC

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

Translate
RonLin
Known Participant
Apr 18, 2018 1:37 PM UTC

OK it only works via HTML5...

Translate
TLCMediaDesign
Inspiring
Nov 15, 2016 1:25 PM UTC

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.

Translate
Lilybiri
Legend
Nov 15, 2016 4:49 PM UTC

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

Translate
TLCMediaDesign
Inspiring
Nov 15, 2016 5:09 PM UTC

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

Translate
TLCMediaDesign
Inspiring
Nov 14, 2016 6:10 PM UTC

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

You need to know the names of the states.

Translate
Known Participant
Nov 15, 2016 9:22 AM UTC

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"

Translate
TLCMediaDesign
Inspiring
Nov 15, 2016 11:14 AM UTC

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

Translate