Skip to main content
Inspiring
February 26, 2021
Answered

html5 createJS code on 1st frame - how do I control the movieclips on other frames

  • February 26, 2021
  • 1 reply
  • 666 views

Hi. All my code is on the first frame.

However, I have the same movieclips etc... on other frames too and I do the same things.

 

Do I have to write out the actionscript again or can I reference the code from another frame.

 

    This topic has been closed for replies.
    Correct answer kglad

    you can use one frame to contain all your code (though this.stop(), this.play(), this. goto's is often easier to place where needed rather than using loops to check the currentFrame of a movieclip and then execute the stop, play, got).

     

    or you can put all your code in an external .js file and use the include panel to add that code to your fla.

    1 reply

    Brainiac
    February 26, 2021

    HTML5 Canvas documents use JavaScript, not ActionScript.

     

    If you want code to be accessible across an entire timeline, you have to define your code as methods of the timeline object.

     

    this.myFunction = function() { bla bla bla

     

    Instead of...

    function myFunction() { bla bla bla

     

    Inspiring
    March 6, 2021

    Excellent.

    So just a quick follow up.

    I was used to coding with adobe builder and we had lots of classes. Basically.we just instantiated the class where we needed it. 

    So with javascript we don't need to create a class and instantiate? We just use the code above this.funcion...

    and use that function wherever we like?

    The problem is that you would end up wth messy code - javascript all over the place.

    Isn't there a nicer way to code with all your code nicely accessible and in folders etc...?

    kglad
    kgladCorrect answer
    Community Expert
    March 6, 2021

    you can use one frame to contain all your code (though this.stop(), this.play(), this. goto's is often easier to place where needed rather than using loops to check the currentFrame of a movieclip and then execute the stop, play, got).

     

    or you can put all your code in an external .js file and use the include panel to add that code to your fla.