T
Tuxedo
How is it possible to pass a parameter via a function that runs upon onload
of an off-screen image? Like for example:
preload_image = new Image(800,600);
preload_image.onload = photo_preloaded(PARAMETER);
preload_image.src = 'images/photo.jpg';
However, this doesn't completely work, because the function
photo_preloaded(PARAMETER) will run regardless of whether the image
finished preloading or not. In normal cases, I do this kind of preloading
without parameters, which works fine, as follows:
preload_image.onload = photo_preloaded;
Instead, I'd like to run the preloading procedure as part of a first
function with the parameter from where it is called at an onclick action
and that is passed onto a second function. Altogether like this:
function first_function(PARAMETER){
preload_image = new Image(800,600);
preload_image.onload = photo_preloaded(PARAMETER);
preload_image.src = 'images/photo.jpg';
}
function photo_preloaded(PARAMETER){
alert(PARAMETER)
}
<a href="..." onclick="first_function('Rambazamba!")">Click here</a>
The above works as far as running and passing the parameters between the
two functions as well as preloading the image. The second function does
however not necessarily run after the image has been preloaded. In fact, it
will run even if photo.jpg does not exist on the server.
Is is possible to run the second function only if the image has been
preloaded, with the parameter? If so, how would this be constructed?
Many thanks for any tips,
Tuxedo
of an off-screen image? Like for example:
preload_image = new Image(800,600);
preload_image.onload = photo_preloaded(PARAMETER);
preload_image.src = 'images/photo.jpg';
However, this doesn't completely work, because the function
photo_preloaded(PARAMETER) will run regardless of whether the image
finished preloading or not. In normal cases, I do this kind of preloading
without parameters, which works fine, as follows:
preload_image.onload = photo_preloaded;
Instead, I'd like to run the preloading procedure as part of a first
function with the parameter from where it is called at an onclick action
and that is passed onto a second function. Altogether like this:
function first_function(PARAMETER){
preload_image = new Image(800,600);
preload_image.onload = photo_preloaded(PARAMETER);
preload_image.src = 'images/photo.jpg';
}
function photo_preloaded(PARAMETER){
alert(PARAMETER)
}
<a href="..." onclick="first_function('Rambazamba!")">Click here</a>
The above works as far as running and passing the parameters between the
two functions as well as preloading the image. The second function does
however not necessarily run after the image has been preloaded. In fact, it
will run even if photo.jpg does not exist on the server.
Is is possible to run the second function only if the image has been
preloaded, with the parameter? If so, how would this be constructed?
Many thanks for any tips,
Tuxedo