Skip to main content
Inspiring
February 17, 2022
Answered

how to call a function on the main timeline from a nested timeline

  • February 17, 2022
  • 1 reply
  • 545 views

Hi Animate Support,

I'm using JavaScript in Canvas and I am trying to find a way to call a function on a movie clip on the main timeline from a movie clip in a nested timeline.  This is important because of the way the graphics work in my FLA.  Here's my code on the main timeline:

 

let bellFrontLt = this.bellFrontLt_mc; 

function positionBellFrontLt()
{
	bellFrontLt.x = 200;
	bellFrontLt.y = 100;
	alert("move bell flower")
}

 

The name of the nested movie clip is all_clip which holds the movie clip (functioning as a button), bellFrontLt_btn.  Neither of the commented-out commands below worked.  Here's my code on the nested clip: 

 

this.bellFrontLt_btn.addEventListener("click", callFunctionMainTimeline.bind(this));

function callFunctionMainTimeline()
{
	//this.parent.positionBellFrontLt();
	//exportRoot.positionBellFrontLt();	
}

 

Any help finding a way to do this will be greatly appreciated.

Zaffer

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

 

You need to make the positionBellFrontLt function a method of the main timeline for being able to call it from another frame or timeline.

 

Like this:

this.positionBellFrontLt = function()
{
	bellFrontLt.x = 200;
	bellFrontLt.y = 100;
	alert("move bell flower")
};

 

Then call it using:

exportRoot.positionBellFrontLt();

 

I hope this helps.

 

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
February 18, 2022

Hi.

 

You need to make the positionBellFrontLt function a method of the main timeline for being able to call it from another frame or timeline.

 

Like this:

this.positionBellFrontLt = function()
{
	bellFrontLt.x = 200;
	bellFrontLt.y = 100;
	alert("move bell flower")
};

 

Then call it using:

exportRoot.positionBellFrontLt();

 

I hope this helps.

 

Regards,

JC

ZafferAuthor
Inspiring
February 18, 2022

Thanks so much João!

Your answer works perfectly.  You saved me from going crazy 🙂

Zaffer

JoãoCésar17023019
Community Expert
Community Expert
February 18, 2022

Awesome!

 

You're welcome!