http://dl.dropbox.com/u/331982/Sandbox/comsat.html <– code
http://dl.dropbox.com/u/331982/Sandbox/comsat.js <– location of javascript file
So, This worked when I had everything all in one file, but I’m not a huge fan of having giant script tags in my HTML.
I get the error that one of the Raphael methods is undefined…. =\
How do I load my script correctly?
Everything is loaded in the <head>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Comsat</title>
<script type="text/javascript" src="http://dl.dropbox.com/u/331982/Sandbox/raphael-min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="http://dl.dropbox.com/u/331982/Sandbox/comsat.js"></script>
<style type="text/css">
body{
background: url(http://i.imgur.com/Ks6Pd.jpg);
}
</style>
</head>
It looks to me like the error is that
initPlayerSelect()is not defined and I think that’s because that function is not in the global scope, but rather it’s defined inside another function scope and thus is not reachable frominitComSat().You will need to make it so that
initPlayerSelect()can be reached from inside theinitComSat()function.One way to do that is to move the
initPlayerSelect()code out of the block it’s in and put it right beforeinitComSat().FYI, this particular error has nothing to do with using JS files or any order of JS files – it’s purely a function scoping issue.
The next error I see is caused because you are running jQuery DOM access code before the page has been loaded here in comsat.js:
This code fails at script load time, which causes
cs_playersto benullorundefinedwhich later causesinitPlayerSelect()to fail.Code like that can’t be run until the page has been loaded. jQuery has
$(document).ready()to run code when the page is loaded.;