bluebomber Posted February 21, 2011 Author Share Posted February 21, 2011 Ok, it looks like I've made a right mess of this, yes I realise what I had done soon after I had done it.I've just tried your solution and it does work in all browsers - so thank you very much for persevering with me.I'm still trying to get my head around what this code is doing - but as far as I can tell we are creating a global array of images and filling up the src's with those of a pre-existing array of images that sit inside the called function.Because the global array exists outside of any function it remains active and accessible even after the function (with its for loop) has ended? Well, you're overwriting the tokyo() function again. But you don't need to take that array out of the function.Look at my code more carefully. What you need is an array of Image() objects that are in the global scope.// Global variablevar TokyoPreloadImages = new Array();function tokyopreload(){ var tokyo = new Array(); tokyo[0]="phototokyo/1.jpg" tokyo[1]="phototokyo/2.jpg" tokyo[2]="phototokyo/3.jpg" var i; for(i=0; i<=tokyo.length; i++) { // Add a new Image() object to the array in the global scope TokyoPreloadImages[i] = new Image(); TokyoPreloadImages[i].src = tokyo[i]; }} Link to comment Share on other sites More sharing options...
Ingolme Posted February 21, 2011 Share Posted February 21, 2011 The global array is empty. When the function is called, it starts adding Image() objects to that global array, that's all. The browser takes care of loading them after that.Local variables of a function (ones declared with "var") are destroyed as soon as the function ends. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.