2010-02-15 126 views
0

我想在movieclip对象上实现下面的控件。当鼠标指针位于对象上时,如果单击鼠标左键并保持单击状态,则重叠动画片段对象的遮罩开始消失。我尝试了MouseEvent.DOWN等,但我没有成功实现此功能。可能我想念一些东西。我可以通过标准的鼠标事件类型来实现吗?还是我需要以另一种方式来实现? 也有可能通过减少alpha属性来淡出蒙版,实际上使鼠标指针下的像素消失?Actionscript鼠标事件问题

回答

0

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

它经常发生这个事件不会被触发,因为对象重叠,我怀疑在这种情况下,它可能是面具。如果是这种情况,您可以简单地使用mouseEnabled = false禁用障碍displayObject上的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检索像素坐标(请注意,位图对象不会派发鼠标事件,因此您需要将其添加到Sprite以用作包装)。 您可以通过getPixel32检索像素实际颜色/ alpha并将其修改为setPixel32

如果您有麻烦,我建议您为此打开一个单独的问题。

希望它能帮助, T.

+0

感谢西奥其实我达到我想要通过使用正确的MOUSE_DOWN,MOUSE_UP,和MOUSE_MOVE事件的影响。实际上,我为每个MOUSE_DOWN,MOUSE_UP注册了两个单独的事件。在MOUSE_UP中,我包含一个object.removeEventListener(MOUSE_MOVE,mousedown),在MOUSE_DOWN中包含一个object.addEventListener(MOUSE_MOVE,mousedown)加上我想要的动作。 – Ponty 2010-02-15 16:24:14