Actionscript鼠标事件问题

发布于 2024-08-21 22:24:44 字数 192 浏览 8 评论 0原文

我正在尝试在影片剪辑对象上实现以下控制。当鼠标指针位于对象上方并且单击鼠标左键并保持单击状态时,与影片剪辑对象重叠的蒙版将开始消失。我尝试了 MouseEvent.DOWN 等,但没有成功实现此功能。也许我错过了什么。我可以通过标准鼠标事件类型来实现这一点还是必须以其他方式实现? 另外,是否可以通过减少 alpha 属性来淡出蒙版,从而真正使鼠标指针下方的像素消失?

i am trying to implement the following control on a movieclip object. When the mouse pointer is over the object and if the left mouse button is clicked and stays clicked then a mask that overlaps the movieclip object is starting to disappear. I tried the MouseEvent.DOWN, etc but i did not succeed to implement this functionality. Probably i miss something. Can i achieve this through standard mouse events types or do i have to implement it another way?
Also is it possible instead to fade out the mask by reducing the alpha attribute, to actually make dissappear the pixel(s) that under the mouse pointer ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千里故人稀 2024-08-28 22:24:44

MouseEvent.MOUSE_DOWN/Mouse.MOUSE_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 ; )
}

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

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

如果您遇到麻烦,我建议您为此提出一个单独的问题。

希望有帮助,
T。

MouseEvent.MOUSE_DOWN/Mouse.MOUSE_UP are indeed the events to use so there most be a problem in your code.

It often happens this event doesn't get triggered because of objects overlapping and I suspect in this case it might be the mask. If this is the case you can simply disabling mouseEvents on the obstructive displayObjects with mouseEnabled = false.

Example :

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 ; )
}

A few quick hints regarding the pixel under the cursor :

You can do it with a Bitmap object.
The pixel coordinates can be retrieved with mouseX, mouseY (note that bitmap objects don't dispatch mouse events so you need to add it to a sprite to use as a wrapper).
You can retrieve the pixels actual color/alpha by getPixel32 and modify it by setPixel32.

If you are having troubles I suggest you open a separate question for that.

Hope it helps,
T.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文