xImgAsyncWait()

Description

This demo is for testing the X function: xImgAsyncWait(). You can view the function source, and view the source of this page for an example of usage.

xImgAsyncWait asynchronously waits (and monitors the status) of newly created or static images. Can be called before or after window.onload, or in the HTML following the last IMG element. During monitoring of image load status, your status function will be called at each iteration. After all images successfully load, your app initialization function is called. If any image fails to load, your error function is called. You can provide error and abort images for those that fail to load.

Demo Message Log

Invocation

There are three different ways to use xImgAsyncWait().

  • Create new images and call it before the onload event, passing it an array of the new Image objects.
  • Create new images and call it after the onload event, passing it an array of the new Image objects.
  • Call it in the HTML immediately after the last IMG element, and don't pass it any array - it will use document.images.

Syntax

* First implementation. Optimizations and fixes will probably follow *

function xImgAsyncWait(fnStatus, fnInit, fnError, sErrorImg, sAbortImg, imgArray)

fnStatus  - A reference to a function which will be called at each
            iteration. It will be passed the same arguments as fnError.
            This is optional. Pass null if not needed.
fnInit    - A reference to your application initialization function.
            It will be called after all images have successfully loaded.
fnError   - A reference to your error function. After all images have
            loaded (or failed to load), it will be called if there was an
            error or abort. This is optional. Pass null if not needed.
            fnError will receive the following arguments:
            n - Total number of images monitored.
            c - Number of images successfully loaded.
            e - Number of images which had an error.
            a - Number of images which were aborted.
sErrorImg - A URL to an image which will be used for any images that
            fail to load due to an error.
sAbortImg - A URL to an image which will be used for any images that
            fail to load due to an abort.                           
imgArray  - An array of newly created Image objects. These images will
            be monitored. If you want all static images (document.images)
            to be monitored then omit this argument.