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

How do I add Javascript to a project so that it works in Flash?

Engaged ,
Aug 28, 2015 Aug 28, 2015

This is an embarrassingly rookie question, but I want to know how to use Javascript in Captivate so that it also works with Flash output.

Let me tell you what I am doing, which works with HTML output:

  • There is a text caption on my slide with a custom variable, numberOfClicks as its content.  The variable has an original value of "0".
  • There is a click box on the slide
  • When the click box is clicked, a very simple advanced action is triggered. The advanced action executes the following script in the current window: numberOfClicks = numberOfClicks + 1;  I know you can use Adobe's built-in "increment" action for this.

Result - When I preview this in HTML5, you can click the click box and watch the value of the variable increment.  When I preview in Flash, the value remains 0 when I click the click box.

How do I get this to work in Flash?

731
Translate
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 ,
Aug 28, 2015 Aug 28, 2015

That is not JS, but advanced actions, or do I misunderstand?

This should work perfectly, it is such a simple action. And SWF output has a much longer history than the new HTML5.. Can you post a screenshot of the advanced action?

Translate
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 ,
Aug 28, 2015 Aug 28, 2015
Translate
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 ,
Aug 28, 2015 Aug 28, 2015

In HTML, you see the value increment. In Flash, this doesn't work.

ScreenShot1.pngScreenShot2.png

Translate
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 ,
Aug 28, 2015 Aug 28, 2015

As you see, I simplified it some more, but I still have the same problem that it doesn't work like I want it to in Flash.

Translate
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 ,
Aug 28, 2015 Aug 28, 2015

So it is JS, not an advanced action. How did you test? You have to deploy also the Flash version in a browser, which means you have to publish it.

Translate
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 ,
Aug 28, 2015 Aug 28, 2015

Yes, I published once as HTML and once as Flash. Here are my Flash settings.   Maybe it is an issue with my browser?

flash settings.png

Translate
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 ,
Aug 28, 2015 Aug 28, 2015

here is a video of my attempts...

Doesnt work in flash.webm - Google Drive

Translate
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 ,
Aug 28, 2015 Aug 28, 2015

I only did see a Preview in your video. You have to publish for SWF output.

Translate
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 ,
Aug 28, 2015 Aug 28, 2015

and when I publish it..

https://drive.google.com/file/d/0B1VqJFseatNrakNzVmswZXRaQlk/view?usp=drivesdk

Translate
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 ,
Aug 28, 2015 Aug 28, 2015

Here is a video of me publishing it.

Flash doesn't work.webm - Google Drive

Translate
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 ,
Aug 28, 2015 Aug 28, 2015
Translate
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 ,
Aug 30, 2015 Aug 30, 2015

Hi RodWard,

Unfortunately, that didn't work. 

That was great info about the Flash Security Settings. Up until now, I didn't have any "trustworthy" files or folders according to the settings. Now a folder on my desktop is "trustworthy".  I published my .swf project to this folder, but like I said before, I have the same problem.  I changed the settings on my Windows operating system, not the "online" settings.  I had trouble adding a folder there;  my operating system insisted that I add a file...

Because of your article I thought of another way to test to see if it there is a Flash Security issue on my PC.  I published the project as Flash and uploaded the zip file to  scormcloud.com, so that the project is hosted on scormcloud.  I found out that it does not work there either.  I assume this rules out any Flash Security settings problem...

Thanks for the help!  If you have any other ideas, I am all ears. 

Ryan

Translate
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 ,
Aug 30, 2015 Aug 30, 2015

Check your JavaScript coding again.

What is the exact code that you are trying to execute?  If it's the code you posted earlier (NumberOfClicks++) that's not a valid JS script.

Translate
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 ,
Aug 30, 2015 Aug 30, 2015

Hi RodWard,

Yes, you are correct. That was my "Javascript".

I guess I don't understand how Captivate and JS work together.  If I were using the DOM API, I would write something like:

var numberOfClicks = 0;

function incrementClicks(){numberOfClicks++};

var clickBox = document.getElementById('clickBox');

clickBox.addEventListener("click",incrementClicks);

I am playing around with JS in Captivate for the first time, so I wanted to started as simple as possible.  I figured because I already defined the variable in Captivate, I didn't have to do it again.  And I don't have to add an event listener to the click box because I assumed it came with one.

But my real problem is that my one line of code works in HTML5.

This also works in HTML5.

numberOfClicks++;

alert("you clicked!");

The inconsistent feedback makes it difficult to test the JS.

Translate
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 ,
Aug 31, 2015 Aug 31, 2015

If you want the JS to work, you need to wrap it in Functions and then you need to call that function.

Translate
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 ,
Aug 31, 2015 Aug 31, 2015

Now my JS looks like this:

function iterate () {numberOfClicks++;}

iterate();

Works in HTML but not Flash.

Translate
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 ,
Aug 31, 2015 Aug 31, 2015

I also tried inserting the first line of code function iterate () {numberOfClicks++;} at the beginning of the standard.js file post-publishing and having the click box trigger the script iterate().

Translate
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 ,
Aug 31, 2015 Aug 31, 2015

I tried two other things to no avail...

Uploaded the project to scormcloud.com with the function in Captivate and uploaded the project to scormcloud.com with the function manually placed at the front of standard.js after publishing.


So in the first attempt, this was the JS in Captivate. 

function iterate () {numberOfClicks++;}

iterate();


In the second attempt, this was the JS in Captivate: iterate();  with function iterate () {numberOfClicks++;} placed at the front of standard.js.

Translate
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 ,
Sep 01, 2015 Sep 01, 2015
LATEST

Hi RodWard,

It has to do something with my computer.  I just downloaded and published the "WeatherData" Adobe Captivate project.    (Sample project here  Common JS interface)

I have the same issue - the published HTML5 works, but the published Flash doesn't.  I am using IE to test both.  And the folder is trusted per Flash settings. 

Translate
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