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

Playing the timeline from javascript

New Here ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

Hi all,

I'm currently trying to play the timeline from an animate project from it's parent webpage/document. I used ot be able to do this with edge animate by with a simple

 

sym.play();

 

I've checked through the posts on here and none of the solutions I've found seem to work for me. this.gotoAndPlay(0), just gives me a console error saying the function doesn't exist. Am I missing something obvious, the trigger I'm using to fire the function is working fine but I just can't seem toget the timeline to play.

 

Many thanks in advance.

TOPICS
Code , Timeline

Views

484

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

Community Expert , Jan 19, 2021 Jan 19, 2021

you have a function in an animate fla canvas project, correct?

 

that function is being called by something somewhere (that probably lacks a reference to the "this" you want) and you've confirmed that function is being called, correct?

 

if so, in the same frame as that function add:

 

var _this=this;

 

and change your code to:

 

_this.gotoAndPlay(0).

Votes

Translate

Translate
Community Expert ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

you have a function in an animate fla canvas project, correct?

 

that function is being called by something somewhere (that probably lacks a reference to the "this" you want) and you've confirmed that function is being called, correct?

 

if so, in the same frame as that function add:

 

var _this=this;

 

and change your code to:

 

_this.gotoAndPlay(0).

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
New Here ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

Thanks for the quick response!

 

I was putting the function( and the event listener) directly into the project.js file after publishing it. I didn't think to put it on the frame itself. That has worked!

 

Many thanks.

 

 

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
Community Expert ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

you're welcome.

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
Community Beginner ,
Jan 28, 2021 Jan 28, 2021

Copy link to clipboard

Copied

Are you able to expand on what you did here and help? I have a simple html animated banner that must not play until a function in the HTML is called. So I have this on frame 1 to stop the timeline.

 

this.stop();

 

Then in HTML I have:

 

<script>
function timelineStart() {
console.log('please play the main timeline!');
this.play();
}
</script>

 

I can call the function timelineStart from Chrome Console and get the console log message please play the main timeline! and an error:

 

Uncaught TypeError: this.play is not a function at timelineStart

 

So function in HTML is working when I call it. But I cannot get the timeline to play when function is called. Are you able to help?

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
Community Expert ,
Jan 28, 2021 Jan 28, 2021

Copy link to clipboard

Copied

what's "this" reference in timelineStart?

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
Community Beginner ,
Jan 28, 2021 Jan 28, 2021

Copy link to clipboard

Copied

'this' was my attempt to target the main timeline in Adobe Animate to play, from the HTML  Just like 'this.stop();' on frame 1 in Adobe Animate which ovbviously works. I tried many variations including:

 

<script>
function timelineStart() {
console.log('please play the main timeline!');
play();
}
</script>

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
Community Beginner ,
Jan 28, 2021 Jan 28, 2021

Copy link to clipboard

Copied

LATEST

Ah, OK I've got it working in two ways. First I used stage.play();

In my HTML:

 

<script>
function timelineStart() {
console.log('please play the main timeline!');
stage.play();
};
</script>

 

Then I added a label in Adobe Animate 'start' and used exportRoot.gotoAndPlay("start");

 

<script>
function timelineStart() {
console.log('please play the main timeline!');
exportRoot.gotoAndPlay("start");
};
</script>

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