Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Actionscript鼠标事件问题_Actionscript 3_Flash Cs4 - Fatal编程技术网

Actionscript 3 Actionscript鼠标事件问题

Actionscript 3 Actionscript鼠标事件问题,actionscript-3,flash-cs4,Actionscript 3,Flash Cs4,我试图在movieclip对象上实现以下控件。当鼠标指针位于对象上方时,如果单击鼠标左键并保持单击状态,则与movieclip对象重叠的遮罩将开始消失。我尝试了MouseEvent.DOWN等,但没有成功实现此功能。也许我错过了什么。我可以通过标准的鼠标事件类型来实现这一点,还是必须以另一种方式实现它? 也可以通过减少alpha属性来淡出遮罩,使鼠标指针下的像素真正消失吗?MouseEvent.mouse\u DOWN/mouse.mouse\u UP确实是要使用的事件,因此代码中存在的问题最多

我试图在movieclip对象上实现以下控件。当鼠标指针位于对象上方时,如果单击鼠标左键并保持单击状态,则与movieclip对象重叠的遮罩将开始消失。我尝试了MouseEvent.DOWN等,但没有成功实现此功能。也许我错过了什么。我可以通过标准的鼠标事件类型来实现这一点,还是必须以另一种方式实现它?
也可以通过减少alpha属性来淡出遮罩,使鼠标指针下的像素真正消失吗?

MouseEvent.mouse\u DOWN
/
mouse.mouse\u UP
确实是要使用的事件,因此代码中存在的问题最多

通常情况下,由于对象重叠,该事件不会被触发,我怀疑在这种情况下可能是掩码。如果是这种情况,您可以使用
mouseEnabled=false
简单地禁用显示对象上的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 ; )
}
有关光标下像素的一些快速提示:

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 ; )
}
你可以用一个物体来做。 可以使用mouseX、mouseY检索像素坐标(请注意,位图对象不发送鼠标事件,因此需要将其添加到精灵以用作包装器)。 您可以通过检索实际颜色/alpha的像素,并通过修改它

如果你有问题,我建议你单独提出一个问题

希望有帮助,
T.

谢谢Theo事实上,通过正确使用鼠标向下、鼠标向上和鼠标移动事件,我达到了我想要的效果。实际上,我为每个鼠标按下和鼠标上升注册了两个独立的事件。在MOUSE_UP中包括一个对象。removeEventListener(MOUSE_MOVE,mousedown)和MOUSE_DOWN中包括一个对象。addEventListener(MOUSE_MOVE,mousedown)加上我想要触发的动作。