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

Call Function on Main Timeline from Global Script

Explorer ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

I have this on the main timeline:

function sayHi () {
	alert ("Hi");
}

I even tried this:

 

this.sayHi = function () {
	alert ("Hi");
}

In Global Script, I tried:

window.exportRoot.sayHi();
window.sayHi = exportRoot.sayHi;

I'm just shooting in the dark right now. I tried following these two posts:

Run local function from global function 

Call function from external html? Animate CC 

The reason why I need to call a function from the Global Script is that I can access Global Script using Captivate, but not any function inside the inserted Animate oam. Thanks.

TOPICS
Code , How to , Timeline

Views

1.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

correct answers 1 Correct answer

Explorer , Jan 23, 2020 Jan 23, 2020

I finally found a way to access inside Animate by clicking on a button in Captivate. I added more to the code to test accessing a function contained inside Animate. First, I created a variable in the Global Script:

var sayHi;

Then, I have this variable equal a function in the timeline. The function created will call another function. The code below is all in the Actions panel in the main timeline. I happened to place it in frame 1:

sayHi = function () {
	letsGo();
}

function letsGo () {
	alert ("L
...

Votes

Translate

Translate
Explorer ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

I finally found a way to access inside Animate by clicking on a button in Captivate. I added more to the code to test accessing a function contained inside Animate. First, I created a variable in the Global Script:

var sayHi;

Then, I have this variable equal a function in the timeline. The function created will call another function. The code below is all in the Actions panel in the main timeline. I happened to place it in frame 1:

sayHi = function () {
	letsGo();
}

function letsGo () {
	alert ("Let's go!");
}

 

Finally, I used this code to call the variable in Global Script containing the function:

var win = document.getElementById('myFrame_Web_5c').contentWindow;
win["sayHi"]();

"Web_5" is the ID for my Animate that I published as an .oam and then inserted into Captivate. I called it "Web_5" in Captivate, but to get its element, I needed to suround it with "myFrame_" then "c" since the oam is located in an iframe. Hopefully this will help anyone else needing this solution. Maybe someone else has a simplier process, but I couldn't find any post explaining this.

 

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
LEGEND ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

What's the purpose of using bracket notation in the function call? That should be functionally identical to:

win.sayHi();

 

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 ,
Jan 24, 2020 Jan 24, 2020

Copy link to clipboard

Copied

LATEST

When I use:

win.sayHi();

it doesn't work. I just retried it right now to make sure. I found the other solution here: https://stackoverflow.com/questions/1723287/calling-a-javascript-function-named-in-a-variable 

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