Newsgroup: it.comp.lang.javascript
Titolo: [!] ImageLoader 2.0


 *
 * NOTE: removing (but not modifying) the comments inside the code,
 * not including this block, won't be considered an actual modification
 * of the program
 */
 
function ImageLoader(){
/* private symbols */
	var _srcs = new Array();
	var _imgs = new Array();
	var _count = 0;
	var _cur = 0;
	var _userdata = null;
	var _onerror_proc = null;
	var _onload_proc = null;
	var _oncomplete_proc = null;
/* private functions */
	/* stub for images' onerror event */
	function _onerror_stub(){
		++ _cur;
		(_cur == _count)?_oncomplete_proc(_userdata):void(0);
		return _onerror_proc(_cur, _srcs[_cur - 1], _imgs[_cur - 1], _userdata);
	}
	/* stub for images' onload event */
	function _onload_stub(){
		++ _cur;
		(_cur == _count)?_oncomplete_proc(_userdata):void(0);
		return _onload_proc(_cur, _count, ((100 * _cur) / _count), _srcs[_cur - 1], _imgs[_cur - 1], _userdata);
	}
	/* class entry point */
	function _main(args){
		for(var _i = 0; _i < args.length; _i ++, _count ++){
			_srcs[_i] = args[_i];
		}
	}
/* public events */
	/* fired when an image fails to load */
	this.onerror = function (cur, src, img, userdata){return true}
	/* fired when an image successfully loads */
	this.onload = function (cur, count, perc, src, img, userdata){return true}
	/* fired at the end of image loading */
	this.oncomplete = function (userdata){}
/* public functions */
	/* store pointers to event handlers and start loading images */
	this.load = function (vData){
		_onerror_proc = this.onerror;
		_onload_proc = this.onload;
		_oncomplete_proc = this.oncomplete;
		_userdata = vData;
		for(_i in _srcs){
			_imgs[_i] = new Image();
 
			with(_imgs[_i]){
				onload = _onload_stub;
				onerror = _onerror_stub;
				src = _srcs[_i];
			}
		}
	}
	/* destroys images */
	this.unload = function (){
		if(arguments.length > 0){
			for(_i = 0; _i < arguments.length; _i ++){
				_imgs[_i] = null;
			}
		}
		else{
			for(_i in _imgs){
				_imgs[i] = null;
			}
		}
	}
	/* destroys private objects */
	this.free = function (){
		_imgs = null;
		_srcs = null;
		// note we can't safely detach event handlers because of the
		// nontransparent pointer handling of JavaScript
	}
/* jump to the entry point */
	_main(arguments);
}
=====================
=== SALUTI & BACI ===
=====================
Ok ragazzi, spero di potervi fornire un po' di esempi pratici in
futuro, e spero che la cosa sia utile a qualcuno
E ora, buona notte...
-- 
January 15, 2028 - Intel announces their new 400THz processor, which
performs 100 billion floating-point operations in the millisecond
before it consumes itself in a nuclear explosion. This is a step up
from AMD's recent processor which simply fries any nearby user with
bolts of plasma energy. Hobbyists are already looking into ways to
overclock the chip. 

: 
insomma non gliene frega proprio niente a nessuno? :(

 wrote in message
Xns904D8F13CB4...@127.0.0.1...


Graaaaaaazzie ;-P !!!!!!!!!!!!
pazienza... tanto ha anche qualche errore

 insomma non gliene frega proprio niente a nessuno? :(
Come?
Ti ho mandato una mail l'altro giorno.... @
z.com
  :-(
-- 
Ciao, Riccardo
------------------------------------------------------------------------
WebMaster: ----> 
http://www.jsdir.com
 <---- (aka 
http://www.jspoint.it
)
------------------------------------------------------------------------
               Nessun traguardo è abbastanza lontano.
------------------------------------------------------------------------

Ti ho mandato una mail l'altro giorno.... @
z.com
  :-(
ho rimesso il mio vecchio indirizzo... 
z.com
 a fine mese chiude i 
battenti :(
ora vado a vedere...
