Highlighted

How to target a function on the main timeline from inside a child movie clip in Animate CC canvas?

Explorer ,
Jan 07, 2018

Copy link to clipboard

Copied

I have an Animate CC Canvas project.  My main timeline is one frame with child movieclips on separate layers. I have a function on the main timeline that I need to call inside a child movieclip. I have tried exportRoot.functionName and this.parent.functionName but neither works. Get js error in browser that object does not support method. I can't figure out how to target main timeline from within child movie clip.

Thanks,

Teresa

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

this.parent.yourfunction();

and use:

this.yourfunction=function(){

}

Views

1.9K

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

How to target a function on the main timeline from inside a child movie clip in Animate CC canvas?

Explorer ,
Jan 07, 2018

Copy link to clipboard

Copied

I have an Animate CC Canvas project.  My main timeline is one frame with child movieclips on separate layers. I have a function on the main timeline that I need to call inside a child movieclip. I have tried exportRoot.functionName and this.parent.functionName but neither works. Get js error in browser that object does not support method. I can't figure out how to target main timeline from within child movie clip.

Thanks,

Teresa

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

this.parent.yourfunction();

and use:

this.yourfunction=function(){

}

Views

1.9K

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 07, 2018 0
Adobe Community Professional ,
Jan 07, 2018

Copy link to clipboard

Copied

this.parent.yourfunction();

and use:

this.yourfunction=function(){

}

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 07, 2018 3
Explorer ,
Jan 07, 2018

Copy link to clipboard

Copied

Thank you that works. However can you explain why function declaration is

this.yourfunction=function(){

}

and not

function yourfunction() {

}

The reason I ask is if I do it your way it works great when called from child movie clip, however if I call the function from another function on the main timeline, gives javascript error. Something about scope I am not understanding.

Thank you,

Teresa

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 07, 2018 2
Adobe Community Professional ,
Jan 08, 2018

Copy link to clipboard

Copied

a named function is only referable from the same timeline and the same frame in which it's defined.  ie, you can't even call it from the same timeline/different frame.

so, while adobe attempted to make javascript in animate similar to actionscript in animate, there are differences.

you're asking why they don't work the same.  i'm saying, while it would be nice if they did work the same, there's no reason to assume they do.

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 08, 2018 2
Explorer ,
Jan 08, 2018

Copy link to clipboard

Copied

Ok, at least I know now why some of my coding is not working as I expected. Thank you.

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 08, 2018 0
Adobe Community Professional ,
Jan 08, 2018

Copy link to clipboard

Copied

you're welcome.

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 08, 2018 2
jambojam LATEST
Explorer ,
Jan 17, 2020

Copy link to clipboard

Copied

This answer is probably close to my need but not sure how to use it.

I need to use a"ClickToGoToAndStopAtFrame...." but the button is in a movie clip. So I think I understand that a button in a  child is trying to move to a frame of the parents timeline and stop. What could I add to the snippet below to get it to jump up to the parent(Scene1) timeline?

 

My instant name is UIButton_3 and I am trying to go to frame 30 of the parent.

this.UIButton_3.addEventListener("click", fl_ClickToGoToAndStopAtFrame_12.bind(this));

function fl_ClickToGoToAndStopAtFrame_12()
{
this.gotoAndStop(30);
}

 

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 17, 2020 0