Organizing Javascript


Is there some kind of technique I can use to better organize all code into a single document?
Hype creates what seems like a separate document for each function I use, be it a timeline action or button action. The resources folder gets pretty crowded not to mention the document tabs for each file on top pretty messy.

(Freelancer) #2

@tofolux - A common technique is to create a separate JS document outside of Hype and put all your code there. You can organize that file any way you want to keep similar functions together. You make Hype aware of this document by referencing it within the HEAD of your HTML file, like so:

<script type="text/javascript" src="AllMyJavaSctipt.js"></script>

I also have a technique that I use a lot where I create one or two big JS ‘startup’ functions within Hype that contain all my major functions. I make every function within those global functions and use comments to organize similar functions. These ‘startup’ functions are executed on scene load in the first scene so that all the functions they contain can be called from there on out.

Either method still requires that you create and assign functions to buttons and timelines as needed, but those functions can now just call your global functions that are inside your ‘startup’ functions.

I hope that makes sense. :slight_smile: Let me know if not! - John