By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Pre-loading images

P: n/a
If the paths to images are hard-coded into an a global array, does that mean
that they are pre-loaded? If not, what is the algorithm to do so?

Thanks,
Jim
Oct 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
JimO wrote:
If the paths to images are hard-coded into an a global array, does that mean
that they are pre-loaded?
No. It creates an array that has members whose values are the paths as
strings. Nothing is loaded into the document.
If not, what is the algorithm to do so?


Everything you need is here (the last post):

<URL:http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/496181e0c60d5b47/f0e23d59c7125841?tvc=1&q=preload+images&hl=en#f0e2 3d59c7125841>

--
Rob
Oct 16 '05 #2

P: n/a
alu

"RobG" <rg***@iinet.net.au> wrote
JimO wrote:
If the paths to images are hard-coded into an a global array, does that mean that they are pre-loaded?
No. It creates an array that has members whose values are the paths as
strings. Nothing is loaded into the document.
If not, what is the algorithm to do so?


Everything you need is here (the last post):

<URL:http://groups.google.com/group/comp....e_frm/thread/4
96181e0c60d5b47/f0e23d59c7125841?tvc=1&q=preload+images&hl=en#f0e2 3d59c71258
41>
--
Rob


....so if an array of paths already exists, you could have something like
this within a function:

var imgName = [];
var imgSRC = []; // your src (path) array
var i = imgSRC.length;

while(--i){
imgName[i] = new Image();
imgName[i].src = imgSRC[i];
}

-alu
Oct 16 '05 #3

P: n/a
Thanks guys!

"alu" <no**@none.com> wrote in message
news:Gq********************@news20.bellglobal.com. ..

"RobG" <rg***@iinet.net.au> wrote
JimO wrote:
If the paths to images are hard-coded into an a global array, does
that
mean that they are pre-loaded?
No. It creates an array that has members whose values are the paths as
strings. Nothing is loaded into the document.
If not, what is the algorithm to do so?


Everything you need is here (the last post):

<URL:http://groups.google.com/group/comp....e_frm/thread/4 96181e0c60d5b47/f0e23d59c7125841?tvc=1&q=preload+images&hl=en#f0e2 3d59c71258 41>

--
Rob


...so if an array of paths already exists, you could have something like
this within a function:

var imgName = [];
var imgSRC = []; // your src (path) array
var i = imgSRC.length;

while(--i){
imgName[i] = new Image();
imgName[i].src = imgSRC[i];
}

-alu

Oct 16 '05 #4

P: n/a
alu wrote:
[...]

...so if an array of paths already exists, you could have something like
this within a function:

var imgName = [];
var imgSRC = []; // your src (path) array
var i = imgSRC.length;

while(--i){
That will pre-decrement i (i will be reduced by 1 before it is tested).
When i gets to 1, it will be decremented to zero, the test returns
false so imgName[0] is not loaded.

You need to post-decrement i so that when it gets to 1, the test is
true, i is reduced to 0 and imgName[0] is loaded. Next time around, i
is zero and the test returns false, ending the loop before i is
decremented any further:

while(i--){
imgName[i] = new Image();
imgName[i].src = imgSRC[i];
}

--
Rob
Oct 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.