Splitting the code

There are three reasons why you should always split the code: first, this practice improves script readability. Remember that script readability is everything when you aren't working on your projects for a while. It's easier to see what this script is supposed to do:

connectToServer();
displaySplashScreen();
startTheMusic();

rather than this one:

// connecting to server
...
... // big set of instructions to connect to the server
...
// display splash screen
...
... // big set of instructions to display the splash screen
...
// starting the music
...
... // big set of instructions to start the music
...

With the first method, the one you'll be using from now on, you can easily see what the script does just looking at the first ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.