Highlighted

Call Function on Main Timeline from Global Script

Explorer ,
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.

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.

 

TOPICS
Code, How to, Timeline

Views

273

Likes

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

Call Function on Main Timeline from Global Script

Explorer ,
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.

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.

 

TOPICS
Code, How to, Timeline

Views

274

Likes

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
Jan 22, 2020 0
Explorer ,
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.

 

Likes

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
Reply
Loading...
Jan 23, 2020 0
Adobe Community Professional ,
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();

 

Likes

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
Reply
Loading...
Jan 23, 2020 0
Explorer ,
Jan 24, 2020

Copy link to clipboard

Copied

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 

Likes

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
Reply
Loading...
Jan 24, 2020 0