Skip to main content
teresah9791625
Known Participant
January 7, 2018
Answered

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

  • January 7, 2018
  • 1 reply
  • 5386 views

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

    This topic has been closed for replies.
    Correct answer kglad

    this.parent.yourfunction();

    and use:

    this.yourfunction=function(){

    }

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    January 7, 2018

    this.parent.yourfunction();

    and use:

    this.yourfunction=function(){

    }

    teresah9791625
    Known Participant
    January 8, 2018

    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

    kglad
    Community Expert
    Community Expert
    January 8, 2018

    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.