Skip to main content
Participant
February 26, 2019
Answered

Animate CC canvas : external JS call function

  • February 26, 2019
  • 1 reply
  • 2139 views

Hello. It's been several days that I search on the net but not finding the solution, I decide to ask it here.

I'm loading a .js file into my Animate CC (Canvas) file.

Since the timeline I can start a function that is in the .js. But the opposite does not work. I have either the message "is not a function" or "undefined function".

How to communicate between the .js and my timeline?

Thanks for your help

    This topic has been closed for replies.
    Correct answer Amiable_genius0D45

    Thanks for your help.

    I found another solution that works (thanks to ):

    canvasTimeline = this;

    I create a global variable that points to the main timeline of my canvas project. I now access everything in my canvas via my global variable since my .js

    I was trying to make it complicated when it was very simple;)

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    February 26, 2019

    Hi.

    There are at least two ways of doing this:

    - Use exportRoot, which is a global reference to the main timeline created by the Animate CC exporter;

    - Pass the main timeline as an argument when instantiating your class.

    For example:

    var player = new Player(this);

    Regards,

    JC

    Amiable_genius0D45AuthorCorrect answer
    Participant
    February 26, 2019

    Thanks for your help.

    I found another solution that works (thanks to ):

    canvasTimeline = this;

    I create a global variable that points to the main timeline of my canvas project. I now access everything in my canvas via my global variable since my .js

    I was trying to make it complicated when it was very simple;)

    JoãoCésar17023019
    Community Expert
    Community Expert
    February 26, 2019

    Nice.

    You can do this as well, but I it's redundant because you already have a global reference to the main timeline (exportRoot).

    Regards,

    JC