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

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

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

Views

4.4K

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

this.parent.yourfunction();

and use:

this.yourfunction=function(){

}

Votes

Translate

Translate
Community Expert ,
Jan 07, 2018 Jan 07, 2018

Copy link to clipboard

Copied

this.parent.yourfunction();

and use:

this.yourfunction=function(){

}

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 07, 2018 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

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 08, 2018 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.

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 08, 2018 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.

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

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
Explorer ,
Sep 07, 2021 Sep 07, 2021

Copy link to clipboard

Copied

I know this is an old thread but just wanted to say thank you. I couldn't get my head around why my script wasn't working as I expected it to (couldn't call functions from within a movieclip). This explained it very well. and saved me a lot of head scratching!

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 ,
Dec 17, 2022 Dec 17, 2022

Copy link to clipboard

Copied

LATEST

you're (belatedly) 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
Explorer ,
Jan 17, 2020 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);
}

 

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