• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to switch the state of an object in javascript?

Community Beginner ,
Nov 14, 2016 Nov 14, 2016

Copy link to clipboard

Copied

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?

Views

3.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 14, 2016 Nov 14, 2016

Copy link to clipboard

Copied

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

You need to know the names of the states.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

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"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

@TLC

I have never used Java to change states, but reading your message above, am I correct in saying...

If I have four buttons North, South, East, West.

Each button has a "Normal" state.

I create a new state on each button named "Invisible".

Would the command cp.changeState("Normal","Invisible"); change the states of all the buttons?

But if I just want to change the state of the South button I would have to rename the states as "SouthNormal" and "SouthInvisbile" and then use cp.changeState("SouthNormal","SouthInvisble");

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

no its a normal smartshape and i can rename the states... one state is called "TestState1", the other "TestState2"... tried to switch it with a button and javascript on the action:

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

and it doesnt work...

i copied the smartshape and the states-names are the same... so does this function not need the name of the smartshape too?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

I have swirched the Normal state for a custom state a lot when creating

toggle buttons, but always with advanced or shared actions. In that case it

is easy that you can have same names to states.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

Is the changeState method only applicable to the cp object? Can it be used at the child object level, like cp.myShape.changeState("oldstate","newstate") ? If not, it would seem that the object model is making a huge assumption that no 2 states would ever be named the same.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

Not sure, I haven't looked into it too deeply. It's not something that is built for external JavaScript, that's just the function that is called when executed as an action. There could also be another parameter depending on the object.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

OK it only works via HTML5...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 06, 2018 Dec 06, 2018

Copy link to clipboard

Copied

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

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2018 Dec 06, 2018

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources