由于影片剪辑重叠而导致的 AS3 MOUSE_OVER 问题
我正在开发一些屏幕上有很多不同按钮的东西。按钮需要使用影片剪辑而不是实际的“按钮”来制作。
我正在使用 Flash CS4 和 ActionScript 3。
我在鼠标悬停时在按钮周围创建了发光效果。这效果很好,只是发光效果为按钮创建了一个大约是实际按钮宽度和高度两倍的碰撞框。我做了一些研究,最终在按钮符号内创建了一个符号,其中仅包含我想要触发按钮的点击区域。这对于触发按钮非常有效。现在,当我将鼠标悬停在按钮上时,它们仅在我点击实际按钮图形本身时才会亮起,而不是发光动画中其周围的框。然而,问题是,由于某种原因,动画中的框仍然阻止在附近的按钮上检测到鼠标悬停(如果框与它们重叠)。
这可能听起来令人困惑,所以这里是一张图片:
绿色区域定义鼠标将激活发光的位置 动画片。
红色区域定义发光动画元件的实际框。
黄色区域定义了按钮中不包含的部分 激活发光动画,因为红色框挡住了 mouseover 事件不会被触发。
我省略了左侧按钮的红色框,以便更容易看到问题,但是请注意,实际上两个按钮周围都有这些框之一,右侧的按钮是刚刚放置在舞台上左侧按钮之后,导致其框位于左侧按钮的顶部。
注意:点击区域和动画都已包含在按钮符号内各自单独的符号中。将动画元件的 mouseEnabled 和 mouseChildren 设置为 false 似乎并没有像我希望的那样达到目的(基于对这个问题的研究)。
注意:当鼠标移动时,动画不会激活(并且不应该激活)被移动到红色区域,它仅在鼠标移动到绿色区域时激活,这是期望的行为,唯一的问题是我根本不希望鼠标事件检测到红色框。
这是按钮类的代码:
package classes{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class glowing_place_marker extends MovieClip {
public static var instances:Array = new Array();
public var is_playing:Boolean=false;
private var is_mouse_over:Boolean = false;
private var animation:MovieClip;
public function glowing_place_marker() {
this.animation = this.place_marker_animation;
this.animation.stop();
this.animation.mouseEnabled = false;
this.animation.mouseChildren = false;
self:instances.push(this);
this.place_marker_hit.addEventListener(MouseEvent.MOUSE_OVER, roll_over_handler);
this.place_marker_hit.addEventListener(MouseEvent.MOUSE_OUT, roll_out_handler);
}
public function roll_over_handler(e:MouseEvent) {
this.animation.play();
this.is_playing=true;
this.is_mouse_over = true;
}
public function roll_out_handler(e:MouseEvent) {
stage.addEventListener(Event.ENTER_FRAME, checkFrame);
this.is_mouse_over = false;
}
function checkFrame(event:Event):void {
if (!this.is_mouse_over) {
if (this.animation.currentFrame==1) {
stage.removeEventListener(Event.ENTER_FRAME, checkFrame);
this.animation.stop();
this.is_playing = false;
}
}
}
}
}
谁能向我解释如何获取动画框(红色框),而不遮挡其下方的按钮? (有效地使鼠标事件无法检测到红色框,因此单击、鼠标悬停等可以直接穿过它到达下面的项目。)
预先感谢您。
I am working on something that has a lot of different buttons on the screen. The buttons need to be made using movieclips, not actual "buttons".
I'm using Flash CS4 and ActionScript 3.
I have created a glow effect around the button on mouseover. This works great, except that the glow effect creates a hitbox for the button about twice the width and height of the actual button. I did some research, and ended up making a symbol inside the button symbol that contains just the hit region I want to trigger the button. This works excellently for triggering the button. Now, when I mouse over the buttons, they only light up when I hit the actual button graphic itself, not the box around it from the glow animation. However, the problem is that for some reason the box from the animation is still blocking mouseover from being detected on nearby buttons (if the box overlaps them.)
This might sound confusing, so here is a picture:
The green area defines where the mouse will activate the glow
animation.The red area defines the actual box for the glow animation symbol.
The yellow area defines the portion of the button that doesn't
activate the glow animation because the red box is blocking the
mouseover event from being fired.I've left out the red box for the button on the left to make it easier to see the problem, take note, however, that there IS in fact one of these boxes around both buttons, the button on the right was just placed on the stage AFTER the button on the left, resulting in its box being on top of the left button's.
NOTE: Both the hit-area and the animation are already contained within their own separate symbols inside the button symbol. Setting the animation symbol's mouseEnabled and mouseChildren to false does not seem to to do the trick like I had hoped it would (based on researching this problem.)
NOTE: The animation does not activate (and it is is not supposed to) when the mouse is moved into the red region, it only activates when the mouse is moved into the green region, this is the desired behavior, the only problem is that I don't want the red box to be detected by mouse events at all.
Here is the code for the button's class:
package classes{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class glowing_place_marker extends MovieClip {
public static var instances:Array = new Array();
public var is_playing:Boolean=false;
private var is_mouse_over:Boolean = false;
private var animation:MovieClip;
public function glowing_place_marker() {
this.animation = this.place_marker_animation;
this.animation.stop();
this.animation.mouseEnabled = false;
this.animation.mouseChildren = false;
self:instances.push(this);
this.place_marker_hit.addEventListener(MouseEvent.MOUSE_OVER, roll_over_handler);
this.place_marker_hit.addEventListener(MouseEvent.MOUSE_OUT, roll_out_handler);
}
public function roll_over_handler(e:MouseEvent) {
this.animation.play();
this.is_playing=true;
this.is_mouse_over = true;
}
public function roll_out_handler(e:MouseEvent) {
stage.addEventListener(Event.ENTER_FRAME, checkFrame);
this.is_mouse_over = false;
}
function checkFrame(event:Event):void {
if (!this.is_mouse_over) {
if (this.animation.currentFrame==1) {
stage.removeEventListener(Event.ENTER_FRAME, checkFrame);
this.animation.stop();
this.is_playing = false;
}
}
}
}
}
Can anyone explain to me how to get the animation's box (the red box), to not block the buttons underneath it? (Effectively make the red box un-detectable by mouse events, so clicks, mouseover, etc. go right through it to the items underneath.)
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在包含按钮点击区域的容器
DisplayObject
(带有发光的容器)上设置mouseEnabled = false
。您仍然希望保留mouseChildren = true
。这样,发光不应再阻止鼠标事件。mouseEnabled
和mouseChildren
的有用之处在于,您可以选择仅禁用容器,或仅容器' 孩子们。这是一本很好的读物:
mouseChildren 和 mouseEnabled
Try setting
mouseEnabled = false
on the containerDisplayObject
(the one with the glow) that contains the hit-area for your button. You will still want to leavemouseChildren = true
. This way, the glow should no longer block mouse events.The useful thing about
mouseEnabled
andmouseChildren
is that you can choose to disable just the container, or just a containers' children.This is a good read:
The power and genius of mouseChildren and mouseEnabled