Просмотр полной версии : Перетаскивание мува, созд. с пом. for ...
BlackChuvak
30.10.2005, 23:58
Циклом for создаются пустые мувы, в них рисуются квадраты...
Как сделать, чтобы потом эти мувы можно было таскать?
опробуй помутить с методом startDrag("имя мува"); где-то на форуме лежали ссылки на словарь AS на русском яз. Там про этот метод усё расписано...
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);
sergwizard
01.11.2005, 03:01
7thsky™, ну зачем такие сложности, особенно для новичка? Можно же намного проще. :)
MovieClip.prototype.qqq = function(){
this.beginFill (random(16000000), random(80)+20);
this.moveTo (0, 0);
this.lineTo (100, 0);
this.lineTo (100, 100);
this.lineTo (0, 100);
this.lineTo (0, 0);
this.endFill ();;
this.onPress = function(){
startDrag(this,false);
}
this.onRelease = this.onReleaseOutside = function(){
stopDrag();
}
}
for(i=0;i<10;i++){
this.createEmptyMovieClip("mc"+i,i);
this["mc"+i]._x = random(500)+30;
this["mc"+i]._y = random(300)+30;
this["mc"+i].qqq();
}
ну можно и так :) Только я не люблю в прототипе прописывать то чего там быть не должно, а то потом вдруг вставляешь один проект в другой смотришь в прототипе функции дублируются :)
BlackChuvak
01.11.2005, 23:48
Блин, я жутко тормозил :)
Я делал способом sergwizard, токо startDrag применялся к ещё не созданному муву, а не через ths ... :D
Работает на vBulletin ® версия 3.7.3. Copyright ©2000-2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Copyright © 1999-2008 Flasher.ru. All rights reserved.