Skip to main content
Known Participant
August 12, 2020
Question

Use javascript in the exported html file to edit a variable in the javascript canvas file.

  • August 12, 2020
  • 1 reply
  • 275 views

Hi,
 
This is my first post here. I hope someone can help?
 
I am familiar with Javascript and Animate. 
 
I have an animate file that I have exported (it is a canvas) and I would like to write some javascript within the html file that can change something in the javascript file.
 
Specifically:

I want to edit the reference to "l3" below to "l1" or "l2" on the fly from javascript within my html file.


// stage content:
(lib.fileName = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{});

// timeline functions:
this.frame_30 = function() {
exportRoot.text.line.gotoAndStop(0);
exportRoot.text.textBlueBG.gotoAndStop("l3");
exportRoot.text.textWhiteBG.gotoAndStop("l3");


}


Any tips or refences to documentations would be great.

 

Thank you.


 

    This topic has been closed for replies.

    1 reply

    Legend
    August 12, 2020

    Why are you publishing as separate HTML and JS files? There's practically never any reason not to publish with them merged into a single HTML file.

     

    Well anyway, once everything's loaded there's no concept of separate files since everything occupies the same browser namespace. So just replace your hard-coded strings with something like exportRoot.myLabel (exportRoot is a global reference to the root timeline) and make sure it's initialized to a default value somewhere. Then you can change it at will in any other code.

    Nick5FF2Author
    Known Participant
    August 12, 2020

    Thank you for your help.

     

    I have just replaced my "l3" "l2" "and "l1" references with a variable outside the abode animate code and it works great.