The run method begins the process of loading the image from the url. The ImageLoader will first call the preRun event callbacks, and if ImageLoaderPreRunEventArgs.cancel is set to true, then the fail and always callbacks will be called. After this, isWorking will be true.
How the image is loaded will be determined by the value of urlMode (see ImageLoaderUrlMode for a comparison of the different methods.)
If workingImageElement is null and an HTMLImageElement is needed (that is, urlMode is ImageLoaderUrlMode.imageUrl), one is created. Event handlers will be added to the image.
If xhr is null and an XMLHttpRequest is needed, one is created. An ajaxOptions object will be added to the request in this case.
Additionally, either imgCrossOrigin or ajaxWithCredentials will be used to decide how Cross-Origin requests will be handled. See those properties for more information on handling Cross-Origin Resource Sharing (CORS) issues.
After all setup has completed, the static event preSend is fired to provide a final opportunity for changes to the request. If ImageLoaderPreSendEventArgs.cancel is set to true, then the fail and always callbacks will be called.
Image loading then begins. When the load completes, the done or fail, (and in either case, the always) events will fire, depending on the result. If successful, the width, height, isHTMLImageElement, and element properties should all have correct values. Otherwise, the error property will contain an error.
Depending on the presence of imagesHolder and the type of image being loaded, the image may temporarily be added to the DOM. If this is the case, the image will be automatically removed when the image is appended somewhere else.
If the urlMode is ImageLoaderUrlMode.ajaxDataUrl or ImageLoaderUrlMode.ajaxXml, and the resulting image is an HTML Image Element (that is, the isHTMLImageElement is true), there is a chance that the src
attribute of element will not be equal to the original url�instead, it may be a data/blob URI. When using the ImageLoaderUrlMode.ajaxDataUrl mode specifically, the processAjaxData callback can be used to access the actual binary data from the response. This is helpful for decryption.
If the url to be loaded is a data URI, it will always be loaded as ImageLoaderUrlMode.imageUrl.
After all callbacks are run, dispose is called on the ImageLoader. Each ImageLoader instance is meant for a single use. To stop the request and not trigger callbacks, use abort or dispose at any time.
For an example, see ImageLoader.