• 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 Insert and call custom Code in CaptivateMainTimeine.as?

Participant ,
Apr 14, 2011 Apr 14, 2011

Copy link to clipboard

Copied

I have been trying to get my head around this, using various blog postings by Jim Leichliter as my guide. However, so far I have been defeated.

This is what I attempted (in Captivate 5):

1) I inserted the following code into CaptivateMaintimeline.as, just above the private function AddEICallbacks() section:

public function helloWorld(){

  alert('hello world');

  }

2) Just above the EICallbacksAdded = true; line, I inserted

ExternalInterface.addCallback("helloWorld", helloWorld);

3) I created a one-slide Captivate 5 presentation with a button whose "On Success" action is set to "Execute Javascript".

4) In the "Execute Javascript" Script_Window, I entered this code:

Captivate.helloWorld();

5) I published the presentation and viewed it in Chrome, Firefox and IE 9, which all reported an error, as follows:

(Chrome) "Uncaught TypeError: Object #<HTMLEmbedElement> has no method 'helloWorld'"

(Firefox) "Captivate is not defined"

(IE 9) "Object doesn't support property or method 'helloWorld'"

6) I changed the script window code to

document.Captivate.helloWorld();

and published and viewded in Chrome in Firefox, with the following results:

(Chrome) "Uncaught TypeError: Object #<HTMLEmbedElement> has no method 'helloWorld'"

(Firefox) "document.Captivate.helloWorld is not a function"

7) I also tried

document.getElementById('Captivate').helloWorld();
and published and viewed in IE 9, getting the same error as previously,
"Object doesn't support property or method 'helloWorld'"
Can anyone see what I am missing here?

TOPICS
Advanced

Views

2.7K

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

correct answers 1 Correct answer

Advisor , Apr 15, 2011 Apr 15, 2011

Hi TrevDev,

The helloWorld() function should be in ActionScript 3.  The alert() call you made in that function is a JavaScript function and cannot be run from flash.  Try copying the CpEISetValue function that's in the CaptivateMainTimeline.as and name it something different... say TrevDevSetValue();  Add your ExternalInterface.addCallback, then try calling TrevDevSetValue() function from JS.  Set a Cp user variable when calling TrevDevSetValue() and have the Cp variable in a caption on screen...

...

Votes

Translate

Translate
Advisor ,
Apr 15, 2011 Apr 15, 2011

Copy link to clipboard

Copied

Hi TrevDev,

The helloWorld() function should be in ActionScript 3.  The alert() call you made in that function is a JavaScript function and cannot be run from flash.  Try copying the CpEISetValue function that's in the CaptivateMainTimeline.as and name it something different... say TrevDevSetValue();  Add your ExternalInterface.addCallback, then try calling TrevDevSetValue() function from JS.  Set a Cp user variable when calling TrevDevSetValue() and have the Cp variable in a caption on screen... so you can see it change.

Also, in your JS, try obtaining the Captivate object through a variable first:

var objCP = document.Captivate;

objCP.TrevDevSetValue('someCpVariable', 1234);

Hope that helps,

Jim Leichliter

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
Participant ,
Apr 15, 2011 Apr 15, 2011

Copy link to clipboard

Copied

Thanks, Jim. Your example got my "proof-of-concept" working.

I had jumped to the unwarranted conclusion that core JavaScript functions were directly accessible from ActionScript. Investigating further as a result of your comment, I discovered the ExternalInterface.call technique for using JavaScript functions in ActionScript when I actually need to. (Ref. http://codingrecipes.com/calling-a-javascript-function-from-actionscript-3-flash and http://www.actionscript.org/resources/articles/745/1/JavaScript-and-VBScript-Injection-in-ActionScri...).

Some background: I wrote my first program in Fortran in 1966 and having been coding ever since. For most of the last two decades, most of what I have written has been in the VB, VB.NET, and ASP.NET worlds, but now I am going through a steep Captivate + ActionScript + JavaScript learning curve as I use Captivate to create course materials for the learning institution where I work. It would be simpler if the materials were only ever going to be run from our web server, but as well as on-campus students we have distance students across the country. We provide the distance students with a computer preloaded with the materials, but not all students have an Internet connection, so I am trying to create materials that can be run stand-alone from the computer's file system or served from a web server with equal facility.

Add in the complication that there are many keyboard shortcuts that Internet Explorer doesn't pass through to Flash, therefore hobbling some of the training and assessment simulations, and you can see that the Captivate presentations have to have sufficient logic built in to detect the environment in which they are running and adjust accordingly. As I will be calling upon this logic over and over again, I would like it to be in one place and access it by a simple JavaScript call from the opening slide of every presentation, thus populating a number of Captivate variables with the environmental information which can then be used to branch the presentation to alternative slides wherever necessary. Therefore, embedding the logic into a customized version of CaptivateMainTimeLine.as seemed the way to go, but if anyone can suggest a better strategy, I am open to all ideas!

Trevor

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
Guest
Apr 15, 2011 Apr 15, 2011

Copy link to clipboard

Copied

I believe the Javascripting must be tested on a web server to work properly. Try publishing and placing files on a web server. They should work.

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
Participant ,
Apr 15, 2011 Apr 15, 2011

Copy link to clipboard

Copied

Thanks for your response. As you will see from the reply I just posted to Jim Leichliter, I need to find solutions that will work stand-alone as well as when the presentation is running from a server, so I can't take the easy way out here.

I believe JavaScript calls will work if they originate from a location that Flash trusts by default, or which has been added into the list of trusted locations in the user's Flash Player Settings Manager (http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html). Therefore, my Captivate lessons will need to include logic that attempts a Javascript call and, if it fails, then steps the user through the process of getting Flash to trust the lesson location.

Best regards.

Trevor

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
Advisor ,
Apr 16, 2011 Apr 16, 2011

Copy link to clipboard

Copied

LATEST

Hi TrevDev,

Looks like you and I come from the same background.  I too come from a VB.NET, ASP.NET programming background and have been getting into AS3 the past couple of years.  If you're still good with your VB.NET, you could try creating a custom .exe Cp wrapper written in .NET. so that it can run on the desktop.  If you're looking for ubiquity, you may want to consider an Adobe AIR wrapper for your Cp projects.  I've created my own .NET .exe wrapper to extend the functionality of Cp.  Although, modifying the MainTimeline will probably accomplish most of what you're after.

Good Luck,

Jim Leichliter

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