Actionscript鼠标事件问题

时间:2010-02-15 00:07:33

标签: actionscript-3 flash-cs4

我正在尝试在movieclip对象上实现以下控件。当鼠标指针在对象上方并且单击鼠标左键并保持单击时,与影片剪辑对象重叠的蒙版开始消失。我尝试了MouseEvent.DOWN等,但我没有成功实现此功能。可能我想念一些东西。我可以通过标准鼠标事件类型实现这一点,还是我必须以另一种方式实现它?  也可以通过减少alpha属性来淡出蒙版,以实际消除鼠标指针下的像素吗?

1 个答案:

答案 0 :(得分:0)

MouseEvent.MOUSE_DOWN / Mouse.MOUSE_UP确实是要使用的事件,因此代码中存在大多数问题。

经常发生这个事件由于对象重叠而没有被触发,我怀疑在这种情况下它可能是掩码。如果是这种情况,您可以使用mouseEnabled = false在阻碍的displayObjects上禁用mouseEvents。

示例:

var background:Sprite,
    foreground:Sprite; // Note: could be MovieClips of course !

// adds a sprite with a pink circle
addChild(background = new Sprite());
background.graphics.beginFill(0xff0099);
background.graphics.drawEllipse(0,0,100,100);

// adds a sprite containing a black box and adds it on top of the circle
addChild(foreground = new Sprite());
foreground.graphics.beginFill(0x000000);
foreground.graphics.drawRect(0,0,100,100);

background.buttonMode = true; // not necessary, just adds the handcursor on rollover to let you debug easier.
foreground.mouseEnabled = false; // the foreground is not clickable anymore, which makes the background clickable


background.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);

function onMouseUp(e:Event):void
{
    foreground.visible = 0; // I let you do the animation here ; )
}

关于光标下像素的一些快速提示:

您可以使用Bitmap对象执行此操作。 可以使用mouseX,mouseY检索像素坐标(请注意,位图对象不会调度鼠标事件,因此您需要将其添加到精灵中以用作包装器)。 您可以按getPixel32检索像素实际颜色/ alpha,并按setPixel32修改它。

如果您遇到麻烦,我建议您另外提出一个问题。

希望它有所帮助, 吨。