Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   Помогите разобраться со скриптом (http://www.flasher.ru/forum/showthread.php?t=77220)

vecher11 20.03.2006 21:02

Помогите разобраться со скриптом
 
Есть скрипт. который имитирует скретч эффект, как на карточках.
Сейчас он работает по нажатию мышки, если кнопка нажата он затирает, если нет, то нет. Нужно чтобы он затирал просто при наведении мыши.
Примечание: wax - имя маски, symbols - имя МС, который открывается при затирании.

Собсно скрипт:

Код:

MovieClip.prototype.startScratch = function(width){
        // each scratch in a new MC to stop it getting too slow. Only graphics inside
        // the bounding box of the MC will need to be updated when it changes...
        this.createEmptyMovieClip(this.i,++this.i);
        var s = this[this.i];
        s.w = width/2;
        s.xLast = s._xmouse;
        s.yLast = s._ymouse;
        s.xPen = s.xLast;
        s.yPen = s.yLast;
        s.xPen2 = s.xPen;
        s.yPen2 = s.yPen;
        s.onEnterFrame = doScratch;
};
// this method is executed every frame to draw in the mask movie clip
// we need to draw with fills because lines do not work as a mask
doScratch = function(){
        // an extra check just in case mouse was released outside movie area
        // (keycode 1 is left mouse button)
        if(key.isDown(1)){
                var xCurr = this._xmouse;
                var yCurr = this._ymouse;
                var dxCurr = xCurr - this.xLast;
                var dyCurr = yCurr - this.yLast;
                this.xLast = xCurr;
                this.yLast = yCurr;
                // the angle (in radians) of the direction of the motion of the mouse
                var theta = -Math.atan2(dyCurr,dxCurr);
                var p1x = xCurr + this.w*Math.sin(theta);
                var p1y = yCurr + this.w*Math.cos(theta);
                var p2x = 2*xCurr - p1x;
                var p2y = 2*yCurr - p1y;
                this.beginFill(0);
                this.moveTo(this.xPen2,this.yPen2);
                this.lineTo(this.xPen,this.yPen);
                this.lineTo(p1x,p1y);
                this.lineTo(p2x,p2y);
                this.endFill();
                this.xPen = p1x;
                this.yPen = p1y;
                this.xPen2 = p2x;
                this.yPen2 = p2y;
        }
};
MovieClip.prototype.endScratch = function(){
        // tidy up all redundant properties and methods
        // (this includes deleting the onEnterFrame event handler)
        for(var p in this){
                if(typeof(this[p])!="movieclip"){
                        delete(this[p]);
                }
        }
};

createEmptyMovieClip("wax",1);
wax.onMouseDown = function(){
        // begin a new scratch every time the mouse button is pressed
        this.startScratch(30);
};
wax.onMouseUp = function(){
        // end the scratch when the button is released
        this[this.i].endScratch();
        gotoAndPlay(2);

};
startAgain = function(){
        // clear all the drawing from the mask
        for(var scratch in wax){
                if(typeof(wax[scratch])=="movieclip"){
                        wax[scratch].removeMovieClip();
                }
        }
        wax.i = 0;
};
// make the MC with the drawing commands into a mask
symbols.setMask(wax);


KUZEN 20.03.2006 22:09

Огромная просьба в дальнейшем пользоваться тегом [code]

vecher11 20.03.2006 22:35

Спасибо, обязательно буду.


Часовой пояс GMT +4, время: 02:49.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.