Показать сообщение отдельно
Старый 14.07.2002, 05:38
john вне форума Посмотреть профиль Отправить личное сообщение для john Посетить домашнюю страницу john Найти все сообщения от john
  № 3  
john
МЕГАФЛЭШЕР

Регистрация: May 1999
Адрес: Россия, Москва
Сообщений: 1,181
Есть один точный способ отследить есть ли такой файл,
метод страдает тем что нельзя при загрузки swf отслеживать текущий размер загруженного файла, пока руки не дошли это порешить, с jpg и mp3 все ок

Если не нужно делать прелоадер с процентами загрузки то пожалуйста:

Код:
//	object for preload swf, mp3 and jpg files.
//	author evgeniy potapenko (john@3wgraphics.net)

//*************************************************************************
//-------------------------------------------------------------------------
//	class image
//-------------------------------------------------------------------------

_global.Image = function(src,mc)
{
	this._targetMovie = mc;
	this.data = new Sound();
	this.data.root = this;
	if (src != undefined) 
	{
		this.tmp_interval = setInterval(this,"load",20,src)// for onLoad creat
	}
}

//-------------------------------------------------------------------------
//	load data
//-------------------------------------------------------------------------

Image.prototype.load = function(src,mc)
{
	clearInterval(this.tmp_interval);
	
	this._targetMovie = mc||this._targetMovie;
	this._src = src;
	
	this.isSwf = src.toLowerCase().indexOf(".swf") > 0;
	
	this.data.onLoad = function(success)
	{
		clearInterval(this.root._traceID);
		this.root.percent = 100;
		this.root.onLoad(success);
	}
	this._traceID = setInterval(this,"_trace",50);
	this.data.loadSound(src);
}

//-------------------------------------------------------------------------
//	get loaded bytes (not worked with swf, only jpeg and mp3)
//-------------------------------------------------------------------------

Image.prototype.getBytesLoaded = function()
{
	return this.data.getBytesLoaded();
}

//-------------------------------------------------------------------------
//	get total bytes
//-------------------------------------------------------------------------

Image.prototype.getBytesTotal = function()
{
	return this.data.getBytesTotal();
}

//-------------------------------------------------------------------------
//	trace
//-------------------------------------------------------------------------

Image.prototype._trace = function()
{
	trace(this.getBytesLoaded())
	if(this.getBytesTotal()<=0)return;
	this.percent = Math.floor((this.getBytesLoaded()/this.getBytesTotal())*10000)/100;
	this.trace();
}

//-------------------------------------------------------------------------
//	default onLoad event
//-------------------------------------------------------------------------

Image.prototype.onLoad = function(success)
{
	if(success)
	{
		if(this._targetMovie != undefined) this._targetMovie.loadMovie(this._src);
		
	}else{
	
		//trace("WRONG URL");
	}
}

//-------------------------------------------------------------------------
//	property src
//-------------------------------------------------------------------------

Image.prototype.addProperty("src",function()
{
	return this._src;
	
},Image.prototype.load)

//-------------------------------------------------------------------------
//	lock _global
//-------------------------------------------------------------------------

ASSetPropFlags(_global, "Image", 7);

//*************************************************************************
//-------------------------------------------------------------------------
//	usage 1
//-------------------------------------------------------------------------

/*

img = new Image("load.jpg");
img.onLoad = function()
{
	myMovie_mc.loadMovie(this.src);
}
img.trace = function()
{
	trace("loaded: "+this.percent+"% of "+this.getBytesTotal/1000+"kb")
}
//-------------------------------------------------------------------------
//	usage 2
//-------------------------------------------------------------------------
img = new Image();
img.onLoad = function()
{
	myMovie_mc.loadMovie("load.swf");
}
img.load("load.jpg")
img.trace = function()
{
	trace("loaded: "+this.percent+"% of "+this.getBytesTotal/1000+"kb")
}
//-------------------------------------------------------------------------
//	usage 3
//-------------------------------------------------------------------------
img = new Image();
img.onLoad = function()
{
	myMovie_mc.loadMovie(this.src);
}
img.src = "load.jpg";
img.trace = function()
{
	trace("loaded: "+this.percent+"% of "+this.getBytesTotal/1000+"kb")
}
//-------------------------------------------------------------------------
//	usage 4
//-------------------------------------------------------------------------
img = new Image();
img.load("load.jpg",myMovie_mc);
img.trace = function()
{
	trace("loaded: "+this.percent+"% of "+this.getBytesTotal/1000+"kb")
}
//-------------------------------------------------------------------------
//	usage 5
//-------------------------------------------------------------------------
img = new Image("load.jpg",myMovie_mc);
img.trace = function()
{
	trace("loaded: "+this.percent+"% of "+this.getBytesTotal/1000+"kb")
}
*/