January 19, 2022
Can I grab a current image state with Javascript?
Comments
(8)
January 19, 2022
Can I grab a current image state with Javascript?
Mike Wilday is the Manager of Learning Technology Solutions at Los Angeles Pacific University. He began using adobe captivate back in 2011 as an instructional media designer and continued using the product since. He developed an instructional media that won a Silver Omni Award titled I.S. Helpdesk - Help my computer is stuck. https://omniawards.com/recent-winners and currently works freelance designing custom captivate solutions for software simulations, websites, and graphic design. 
Guide 3 posts
Followers: 6 people
(8)

I am looking for a way to grab the current image state and save it as a user variable for referencing later in a project. I am looking to grab a user’s state selection and then reveal different images later in the project. Any insight you could provide would be helpful.

8 Comments
2022-01-26 10:43:31
2022-01-26 10:43:31

You got a JS answer indeed. But did you ever check this blog post where I use rather easy advanced actions to change states in other slides?

http://blog.lilybiri.com/choose-and-use-personal-avatars

 

Like
()
2022-01-25 16:58:45
2022-01-25 16:58:45

Another way would be to use the following…

cp.getCurrentStateNameForSlideItem(“objectName”);

 

Like
(1)
(4)
>
Greg Stager
's comment
2022-01-25 17:26:46
2022-01-25 17:26:46
>
Greg Stager
's comment

Really, Greg, that works? Would be easier and more direct than my approach with cp.model.data. Will check that out and it definately goes into my selection of hidden cp methods.

Like
()
>
Greg Stager
's comment
2022-01-25 17:35:54
2022-01-25 17:35:54
>
Greg Stager
's comment

Greg, you need to publish that book, or at least a user cheat sheet with all of these great options. This is exactly what I needed. How are you figuring out all of these powerful calls. I am transforming and simplifying the use of advanced actions with Javascript. It’s so much faster and easier to do. Do you have a current list somewhere with the basic actions? I want to play an audio file that I’ve imported and used in my project triggering it with javascript. would cp.playAudio(“name of audio”) work? I need to get hold of a set of these captivate calls so  I can implement them in my project.

Like
()
>
MICHAEL WILDAY
's comment
2022-01-25 18:45:11
2022-01-25 18:45:11
>
MICHAEL WILDAY
's comment

Works like a charm and powerful in conditional actions.

Many of the new ones I learned through studying the console.

Launch a project preview and open the console.

Start typing cp.

…then see all the commands that appear!

At that point – it is much trial and error to figure out the parameters to make them work.

Audio is tough to work with because Captivate changes the name of your uploaded audio file to some random number.

My approach has been to tie playing audio to a discrete “hidden” click box on the screen somewhere. Then I use JavaScript to perform the click on that box when I need it.

Like
(1)
>
Greg Stager
's comment
2022-01-25 18:53:58
2022-01-25 18:53:58
>
Greg Stager
's comment

I saw your comments about that on another post. So, rather than playing the audio you initiate the click box to start the audio. Not as intuitive. I was hoping to trigger a variety of audio files from an array. So the effect is different each time the trigger occurs. I’m gonna have to give this a try.

Like
()
2022-01-25 16:47:38
2022-01-25 16:47:38

Awesome. That is extremely helpful. I am very familiar with arrays I just wasn’t sure of the call to retrieve the state of the image. Thank you!

Like
()
2022-01-25 13:27:08
2022-01-25 13:27:08

Hi Michael,

there’s a way with javascript. All states of an object in Captivate are listed in an Array. This is a kind of listing of all states (items). Each item has an index number depending on the position in the (states)-Array.

Assuming your user variable to store the current image state index is called myImageCurrentStateIndex and the image object is called myImageObject then you can grab the current state with

myImageCurrentStateIndex = cp.model.data.myImageObject.currentState;

This is all related to the data stored in the CPM.js which accompanies each published Captivate HTML5 project. However, what you get as myImageCurrentStateIndex is the index number (position) within that particular myImageObject (states)-Array. Be aware that Array index numbers start counting with 0 (zero).

Now you could create another variable (Array as well) to store your state names of myImageObject. Like i.e.

myImageObjectStateNames = [“Normal”, “red”, “blue”, “green”, “purple”];

So if the grab via cp.model.data returns for instance 2 then you can get the particular state name by scripting

myImageCurrentStateName = myImageObjectStateNames[myImageCurrentStateIndex];

This would return the state name “blue”.

Hope this helps

Klaus

Like
()
Add Comment