Показать сообщение отдельно
Старый 31.10.2005, 00:35
7thsky™ вне форума Посмотреть профиль Отправить личное сообщение для 7thsky™ Найти все сообщения от 7thsky™
  № 3  
Ответить с цитированием
7thsky™
Flash Aксакал
 
Аватар для 7thsky™

Регистрация: Jun 2005
Сообщений: 636
Код:
MovieClip.prototype.drawRect = function (x, y, width, height, color, alpha) {
	this.beginFill (color, alpha);
	this.moveTo (x, y);
	this.lineTo (x + width, y);
	this.lineTo (x + width, y + height);
	this.lineTo (x, y + height);
	this.lineTo (x, y);
	this.endFill ();
}

this.draw = function (container, prototypeObject) {
	if (typeof container == 'movieclip') {
		for (var i = 0; i < 10; i++) {
			var mc = container.createEmptyMovieClip ('mc' + i, i);
			var color = Math.floor (Math.random () * 16000000);
			var alpha = 50 + 50 * Math.random ();
			var width = 100 + 100 * Math.random ();
			var height = 70 + 70 * Math.random ();
			var x = Stage.width * Math.random ();
			var y = Stage.height * Math.random ();
			mc.__proto__ = prototypeObject;
			mc._x = x; mc._y = y;
			mc.init (width, height, color, alpha);
		} // end for
	} // end if
};

var o = new Object ();
o.__proto__ = MovieClip.prototype;
o.yy = null;
o.xx = null;

o.init = function (width, height, color, alpha) {
	// рисуем квадрат
	this.drawRect (0, 0, width, height, color, alpha);
	// определяем обработчик
	this.onPress = this.__onPress;
};

o.__onPress = function () {
	this.yy = this._ymouse;
	this.xx = this._xmouse;
	
	this.onRelease = this.__onRelease;
	this.onReleaseOutside = this.__onRelease;
	this.onEnterFrame = this.__onEnterFrame;
};

o.__onRelease = function () {
	this.onEnterFrame ();
	
	delete this.onEnterFrame;
	delete this.onRelease;
	delete this.onReleaseOutside;
};

o.__onEnterFrame = function () {
	var y = this._parent._ymouse - this.yy;
	var x = this._parent._xmouse - this.xx;
	
	var k;
	
	// x
	k = (x - this._x) * .3;
	if (Math.abs (k) < .3) {
		this._x = x;
	} else {
		this._x += k;
	} // end if
	
	// y
	k = (y - this._y) * .3;
	if (Math.abs (k) < .3) {
		this._y = y;
	} else {
		this._y += k;
	} // end if
};


this.draw (this, o);


Последний раз редактировалось 7thsky™; 31.10.2005 в 11:54.