当鼠标离开CLIP1动画code没有被解雇,但鼠标里面夹2 [英] Animation code not fired when mouse is out Clip1 but mouse is inside clip 2

查看:97
本文介绍了当鼠标离开CLIP1动画code没有被解雇,但鼠标里面夹2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

当我移动鼠标光标出素材1,但高于素材2,素材1的MOUSE_OUT不起作用。

后市展望:

当然鼠标里面夹2,鼠标的位置是夹1已经之外,因此函数MOUSE_OUT()素材1,应火$里面C $℃。

全部code:

我附上完整的code为止。

 进口的flash.display.MovieClip;

cat1.addEventListener(的MouseEvent.MOUSE_OVER,MOUSE_OVER);
cat1.addEventListener(的MouseEvent.MOUSE_OUT,MOUSE_OUT);
cat2.addEventListener(的MouseEvent.MOUSE_OVER,MOUSE_OVER);
cat2.addEventListener(的MouseEvent.MOUSE_OUT,MOUSE_OUT);
cat3.addEventListener(的MouseEvent.MOUSE_OVER,MOUSE_OVER);
cat3.addEventListener(的MouseEvent.MOUSE_OUT,MOUSE_OUT);
cat4.addEventListener(的MouseEvent.MOUSE_OVER,MOUSE_OVER);
cat4.addEventListener(的MouseEvent.MOUSE_OUT,MOUSE_OUT);
cat5.addEventListener(的MouseEvent.MOUSE_OVER,MOUSE_OVER);
cat5.addEventListener(的MouseEvent.MOUSE_OUT,MOUSE_OUT);

功能MOUSE_OVER(E:的MouseEvent)
{
    squareEaseOut(e.currentTarget,[将scaleX,1.5,的scaleY,1.5]);
}

功能MOUSE_OUT(E:的MouseEvent)
{
    squareEaseOut(e.currentTarget,[将scaleX,1的scaleY,1);
}

VAR iSquareEasingInterval:INT;

//简单的方形宽松政策,这可以捕捉几个属性进行动画处理
功能squareEaseOut(MC:对象,瓦尔:阵列)
{
    VAR检查:= 0;
    clearInterval(iSquareEasingInterval);

    VAR INI:阵列=新的Array();
    VAR accelNum:数= 0;
    VAR jerkNum:数= 0;
    VAR varsLength:UINT = vars.length / 2;

    对于(VAR我:UINT = 0; I< varsLength;我++)
    {
        INI [i] = MC [瓦尔[2 * I]];
    }

    功能animateEasing()
    {
        检查++;
        如果(比较(MC [瓦尔[0] +(0.25 *(瓦尔[1]  -  INI [0]))/((1 + accelNum)*(1 + accelNum)),瓦尔[1]))
        {
            VAR结束=新的日期();
            跟踪(时间流逝+(结束 -  startD));

            clearInterval(iSquareEasingInterval);
            accelNum = 0;
            jerkNum = 0;
            对于(VAR记者:UINT = 0; J< varsLength; J ++)
            {
                MC [瓦尔[2 * j]的] =瓦尔[(2 * j)条+ 1];
            }
            返回;
        }
        对于(VAR K:UINT = 0; K< varsLength; k ++)
        {
            MC [瓦尔[2 * K] + =(0.26 *(瓦尔[(2 * k)的1]  -  INI [K]))/((1 + accelNum)*(1 + accelNum));
        }
        accelNum + = 0.150+(jerkNum * jerkNum * jerkNum);
        jerkNum + = 0.09;
    }
    功能比较(一:数,B:号码)
    {
        如果(瓦尔[1]≥INI [0])
        {
            返回a取代; B;
        }
        否则如果(瓦尔[1]; INI [0])
        {
            返回&所述; B;
        }
    }
    VAR startD =新的日期();
    iSquareEasingInterval = setInterval的(animateEasing,20);
};
 

解决方案

现在的问题是,你正在调用同样的方法 squareEaseOut 当任何鼠标或鼠标移出事件发生。既然你移动鼠标,立即出一个短片剪辑和其他,同样的方法被调用两次,第一次为鼠标了(旧影片剪辑),然后为鼠标在新的影片剪辑。如您使用的是的setInterval 和结算的时间间隔,以及在每次调用这不会导致正确的行为的第二个电话会覆盖第一个。

虽然可能有多种方式来解决这个问题,最简单的方法是有老鼠出来,鼠标移到不同的方法,尽管这可能会导致一些code重复。或者,你可以等待第一个动画完成,然后调用另外一个。

您还可以查看可用来实现你想要的各种补间图书馆,但那不是东西,我要在这里做广告。

希望这有助于。

Problem:

When I move the mouse cursor out of Clip 1 but is above Clip 2, the MOUSE_OUT of Clip 1 does not work.

Expectation:

Granted that the mouse is inside Clip 2, the location of the mouse is outside of Clip 1 already, so the function mouse_out() of Clip 1 should fire the code inside it.

Full code:

I am attaching the full code so far.

import flash.display.MovieClip;

cat1.addEventListener(MouseEvent.MOUSE_OVER,mouse_over);
cat1.addEventListener(MouseEvent.MOUSE_OUT,mouse_out);
cat2.addEventListener(MouseEvent.MOUSE_OVER,mouse_over);
cat2.addEventListener(MouseEvent.MOUSE_OUT,mouse_out);
cat3.addEventListener(MouseEvent.MOUSE_OVER,mouse_over);
cat3.addEventListener(MouseEvent.MOUSE_OUT,mouse_out);
cat4.addEventListener(MouseEvent.MOUSE_OVER,mouse_over);
cat4.addEventListener(MouseEvent.MOUSE_OUT,mouse_out);
cat5.addEventListener(MouseEvent.MOUSE_OVER,mouse_over);
cat5.addEventListener(MouseEvent.MOUSE_OUT,mouse_out);

function mouse_over(e:MouseEvent)
{
    squareEaseOut(e.currentTarget,["scaleX",1.5,"scaleY",1.5]);
}

function mouse_out(e:MouseEvent)
{
    squareEaseOut(e.currentTarget,["scaleX",1,"scaleY",1]);
}

var iSquareEasingInterval:int;

//simple square easing, this can capture several properties to be animated
function squareEaseOut(mc:Object,vars:Array)
{
    var checker:int = 0;
    clearInterval(iSquareEasingInterval);

    var ini:Array = new Array();
    var accelNum:Number = 0;
    var jerkNum:Number = 0;
    var varsLength:uint = vars.length / 2;

    for (var i:uint = 0; i<varsLength; i++)
    {
        ini[i] = mc[vars[2 * i]];
    }

    function animateEasing()
    {
        checker++;
        if (compare(mc[vars[0]]+(0.25 * (vars[1] - ini[0])) / ((1 + accelNum) * (1 + accelNum)),vars[1]))
        {
            var end = new Date();
            trace("Time lapse: "+(end - startD));

            clearInterval(iSquareEasingInterval);
            accelNum = 0;
            jerkNum = 0;
            for (var j:uint = 0; j<varsLength; j++)
            {
                mc[vars[2 * j]] = vars[(2 * j) + 1];
            }
            return;
        }
        for (var k:uint = 0; k<varsLength; k++)
        {
            mc[vars[2*k]] +=  (0.26 * (vars[(2*k)+1] - ini[k])) / ((1 + accelNum) * (1 + accelNum));
        }
        accelNum += 0.150+(jerkNum*jerkNum*jerkNum);
        jerkNum +=  0.09;
    }
    function compare(a:Number,b:Number)
    {
        if (vars[1]>ini[0])
        {
            return a>b;
        }
        else if (vars[1]<ini[0])
        {
            return a<b;
        }
    }
    var startD = new Date();
    iSquareEasingInterval = setInterval(animateEasing,20);
};

解决方案

The problem is that you are calling the same method squareEaseOut when any mouse over or mouse out event occurs. Since you are moving your mouse immediately out of one Movie Clip and on to the other, the same method gets called twice, first for the mouse out (for the old movie clip) and then for the mouse over of the new Movie Clip. This will not result in correct behavior as the second call will override the first one as you are using setInterval and clearing the interval as well on every call.

While there may be multiple ways to solve this, easiest way would be to have separate methods for mouse out and mouse over, although that might lead to some code repetition. Or, you could wait for the first animation to finish and then call the other one.

You can also look at various tweening libraries available to achieve what you want, but thats not something that I would advertise here.

Hope this helps.

这篇关于当鼠标离开CLIP1动画code没有被解雇,但鼠标里面夹2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆