Skip to main content
July 27, 2006
Question

JavaScript in Click Attempts

  • July 27, 2006
  • 4 replies
  • 1356 views
Hello, All!

After the last defined click attempt, I want to execute JavaScript to display a final "correct answer" pop-up message and then have the movie advance to the next slide. What is the script to do that?

Thanks!
    This topic has been closed for replies.

    4 replies

    Participating Frequently
    July 31, 2006
    I'm not sure why your page cannot be displayed.

    If you haven't modified your Captivate publishing files then captivatemovieid will be Captivate1

    So replace the line:

    var cp = window.captivatemovieid || window.document.captivatemovieid

    with:

    var cp = window.Captivate1 || window.document.Captivate1

    Capvate1 comes from id attribute (id="Captivate1") in the object tag.

    The name attribute for the embed tag is missing in the standard template so this won't work for non IE browsers unless you add it.

    If you need to support nonIE browsers replace this text: <embed

    with: <embed name="Captivate1"
    July 31, 2006
    Here is what I have put into the htm file:

    <!-- saved from url=(0013)about:internet -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    " http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Document Center Presentation</title>
    <script type="text/javascript">
    function message(msg) {var cp = window.Captivate1 || window.document.Captivate1;
    if(msg == null) {msg = "Click Continue";}
    cp.SetVariable("rdcmndPause","1");
    alert(msg);
    cp.SetVariable("rdcmndResume","1");
    cp.SetVariable("rdcmndNextSlide","1");};
    </script>

    </head>

    <body>
    <center>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=" http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="1024" height="768" ID="Captivate1">
    <param name="movie" value="Find a DocTestAttempts.swf">
    <param name="quality" value="high">
    <param name="menu" value="false">
    <param name="loop" value="0">
    <embed src="Find a DocTestAttempts.swf" width="1024" height="768" loop="0" quality="high" pluginspage=" http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>
    </object>
    </center>
    </body>
    </html>

    And in the After last attempt drop down in CP I've set it to Execute JavaScript -> message()

    What is not correct?

    Thanks for all of your help with this!!
    Participating Frequently
    August 1, 2006
    The file you posted works for me with my example, and I have set up a button in captivate to execute javascript-> message() after three attempts. So that means it must be the something in your cp file that is preventing this from working.

    If you can set up a zip somewhere for me to download containing your cp file and I can take a look at it for you.
    Participating Frequently
    July 29, 2006
    To send line breaks entered into Captivates javascript dialog use \r instead of \n.

    If you are sending line breaks from HTML use \n
    Participating Frequently
    July 29, 2006
    In your html enter the following script in the head of the document. It will pause the movie until the message you are sending is acknowledged and then play the next slide.

    <script type="text/javascript">
    function message(msg) {
    // Create a reference to the captivate movie.
    // NB: change cpativatemovieid to whatever you movie is called in the HTML.
    // window.captivatemovieid is the value of name from the embed tag
    // and is used by non IE browsers.
    // window.document.captivatemoiveid is the value of id from the object tag
    // and is used IE.
    var cp = window.captivatemovieid || window.document.captivatemoviveid;

    // you can send the message with the function call or define it here.
    // e.g message('hello world'), or message() and define msg here
    if(msg == null) {
    msg = "define the message here";
    }


    // prevent the movie from playing the next slide
    // until after the alert has been finished
    cp.SetVariable("rdcmndPause","1");

    // display the message to the user.
    alert(msg);

    // Start the movie again
    cp.SetVariable("rdcmndResume","1");
    // Advance movie to next slide
    cp.SetVariable("rdcmndNextSlide","1");
    };
    </script>

    In captivate set your button to "Execute javascript",
    then in the javascript dialog enter either: message('hello world') or if you
    have defined your message in the HTML page: message()


    HTH
    July 31, 2006
    Thanks for the response!

    In Captivate, I entered the button click options as follows:
    On success: Go to Next slide
    Allow user: 2 attempts
    After last attempt: Execute JavaScript
    message('my message contents here')

    When I publish the movie and ran it, nothing occurs when I click incorrectly a third time. The movie pauses and continues only after a successful button click.

    I then tried your other suggestion.

    In the html file, I entered the button click options as follows:
    On success: Go to Next slide
    Allow user: 2 attempts
    After last attempt: Execute JavaScript
    message()
    I copied your code and pasted it in the header of the file. When I published the movie and ran it, it was attempting to open an internet page and failed with the standard "page cannot be displayed" message.

    What am I doing wrong?

    Thanks!
    Captiv8r
    Legend
    July 27, 2006
    Hi bytefun and welcome to the community

    Try this code:

    alert('Sorry, the correct answer is:\n\nInsert correct answer text here.')

    Post back if any of this is unclear and we'll try to help further.

    Cheers... Rick
    Captiv8r
    Legend
    July 27, 2006
    Hi again bytefun

    Sorry, the \n\n is normally used to force a liine break in the Alert dialog. Looks like Captivate is munging the code. Working to see if I can find a way to prevent that.

    Cheers... Rick
    Captiv8r
    Legend
    July 27, 2006
    Hi again bytefun

    Okay, if it's important to you to have the JavaScript present a dialog with verbiage that looks like this:

    Sorry, this is incorrect.

    The correct response is:
    Click here and do that.

    As opposed to:

    Sorry, this is incorrect. The correct response is: Click here and do that.

    You will need to output your Captivate as .SWF with an associated .HTM page. You would then declare a JavaScript function in the head area of the associated .HTM page and call that function from the same location as where you entered the alert earlier.

    If this interests you, post back and I'll be happy to provide more detail. It's really not quite as difficult as it may appear. It will just take a bit to explain and there is no need for me to explain it all if you don't want to go there.

    Cheers... Rick