See an example here: http://www.soulsolutions.com.au/examples/VE62/loadondemand.htm (view source for full code)
In the recent release of the control, Version 6.2 a new feature was introduced to allow for a function of your choice to be called once the script was loaded. To achieve this you append the parameter onScriptLoad to the VE API url like so:
The function loadVEAPI is called when the user clicks our link, using a simple flag to ensure we don’t load the script again. We first set a simple animated gif as the background for our map div, as the control is loading this provides feedback to our users. You can get your own animation from here: http://www.ajaxload.info
Important: For FireFox Virtual Earth includes a compatibility file, this file must be included before the Virtual Earth script. I found in testing this was not the case when loaded on demand. The fix is to manually load this file (if required) prior to the VE Script.
Lastly we load the Virtual Earth script passing our function name “onscriptload” to be called when it is loaded. I made a little helper function “appendJS” to neaten up the code, it creates a script element, sets the correct attributes and appends it to the head of the page.
When the script has loaded our “onscriptload” function is called as expected. We simply turn off our animation and load our Virtual Earth map as usual. Pretty simple hey?
See it in action here: http://soulsolutions.com.au/examples/VE62/loadondemand.htm
The Virtual Earth script is now cached for around 1 month so once it is loaded the first time in your browser it will load very quickly on subsequent pages. For testing you will need to clear your browser cache.