In my main Web Page (Viewer.aspx) I have a javascript script tag like this
<script language="javascript" type="text/javascript">
function initialize() {
var map = $find('Map1');
map.add_mouseMove(mouseMove);
}
</script>
Within those script tags I have a function. Is it possible to call another function that is in a different script tag like this?
<script language="javascript" type="text/javascript" src="Resources/JavaScript/proj4js-combined.js">
function mouseMove(sender,eventArgs) {
var source = new Proj4js.Proj('EPSG:3116');
var dest = new Proj4js.Proj('WGS84');
var p = new Proj4js.Point(px, py);
Proj4js.transform(source, dest, p);
}
</script>
As per your comment, here’s what T.J. was talking about – you need to turn your second script block into something like this:
…but you should really just move the inline code block (what’s inside of the 2nd
<script>tag in my answer) to an external Javascript file.Edit 1: What’s the programming background you’re coming from? If it’s something like C# or Java, you’ll need to forget what you know about those and approach Javascript completely differently. Javascript is an interpreted language, not a compiled one; among other things, this means that the order in which your functions are declared matters.
When I say “function declaration,” I mean anything that looks like this:
This tells the Javascript interpreter about a new function, called
myNewFunction, whose body consists of whatever is in the curly braces.Here’s an example of what I’m talking about when I say you are using a function before you’ve declared it. Consider the following block of code (in isolation from any other Javascript, say, in an external Javascript file):
This will work as expected, because
foo()was declared before you called it. However, what (it sounds like) you’re trying to do is analogous to this:If you were to run this second Javascript snippet, it wouldn’t work, because you’re calling a function before it was declared.*
*Footnote: this is not actually the case, because using this syntax (
function foo() { ... }) does something special and magical in Javascript. My particular example will actually work, but it illustrates the problem you’re having.