Right. I think I finally understand what you mean. So the JS scripts are being executed as in an ordinary file, from top to bottom, as the page loads. (I thought the external .js files were merely loaded, not executed, and then responded to "browser callbacks" when events were triggered). Global statements are being executed first because they are not contained in functions. And window.onload=initialize; means:
1) Read this global statement, note the name of the function ( initialize(); ); 2) Wait until AFTER the body IS loaded; 3) Execute function noted in 1) (initialize();) So according to the above, one has to swap the script declarations like this: //ONE <script type="text/javascript" src="http://maps.google.com/jsapi? key=my_key"></script> <script type="text/javascript"> google.load("maps", "2"); </script> <script type="text/javascript"> var gyms = [array]; </script> //TWO <script src="/javascripts/application.js?1232124679" type="text/ javascript"></script> I just did that and now at least the site has no JS errors, which is also some progress I guess. I appreciate you sticking through with me. / Vahagn On Jan 16, 6:27 pm, "warden [Andrew Leach - Maps API Guru]" <[email protected]> wrote: > On Jan 16, 5:05 pm, railscoder <[email protected]> wrote: > > > All right then, I'll have to figure out THE CODE by myself. > > I'm sorry if I'm pitching my answers wrongly. > > Your code has this, inter alia: > <script src="/javascripts/application.js?1232124679" type="text/ > javascript"></script> > <script type="text/javascript" src="http://maps.google.com/jsapi? > key=...."></script> > > so application.js is loaded and run first before the API script. > application.js contains > window.onload=initialize; > window.onunload=GUnload; > > and at the time the "window.onunload" line is reached, GUnload() > hasn't been loaded because that only arrives with the API script, so > that line fails. Script statements which are not contained within > functions (ie they are in global context) are executed in the order > they are encountered within each script block, which is why those > lines in application.js are executed first. > > Andrew --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---
