有一个主要的容器包含很多其他的动画片段,在这些CHILD1动画片段中,还有一个CUBE和一个IMAGE动画片段。我想仅为IMAGE动画片段禁用鼠标事件,是否可能?
CONTAINER
-CHILD1
-CUBE //this has mouse events!
-IMAGE //want to disable the mouse events for this!
-CHILD2
-CUBE //this has mouse events!
-IMAGE //want to disable the mouse events for this!
-CHILD3
-CUBE //this has mouse events!
-IMAGE //want to disable the mouse events for this!
有什么想法吗?谢谢! CHILD的代码块:
private function added(e:Event) {
removeEventListener(Event.ADDED_TO_STAGE, added);
addEventListener(MouseEvent.MOUSE_UP, NEXT);
}
public function NEXT(e:MouseEvent) {
//OB is the instance name of the IMAGE
if(e.target.name == "OB"){
e.stopImmediatePropagation();
return;
}
OB.gotoAndStop(Main.ID);
}
[解决] 要禁用特定孩子的事件监听:
private function added(e:Event) {
mouseEnabled = false; //This is the clue.
OB.mouseEnabled = false;
OB.mouseChildren = false;
removeEventListener(Event.ADDED_TO_STAGE, added);
cube.addEventListener(MouseEvent.MOUSE_UP, NEXT);
}
答案 0 :(得分:2)
如果您的鼠标侦听器已附加到图像,请设置IMAGE的mouseEnabled& mouseChildren属性在构造函数中为false(或者如果在Flash CSX中使用时间轴),则在IMAGE对象时间轴上(在第一帧上)设置mouseEnabled& mouseChildren为false。
这将是您发布的代码的更改(不确定您所谓的CUBE实例):
private function added(e:Event) {
removeEventListener(Event.ADDED_TO_STAGE, added);
CUBE.addEventListener(MouseEvent.MOUSE_UP, NEXT);
OB.mouseEnabled = false;
OB.mouseChildren = false;
}
public function NEXT(e:MouseEvent) {
OB.gotoAndStop(Main.ID);
}
答案 1 :(得分:1)
为图像指定实例名称(假设它是“OB”)并且:
private function added(e:Event)
{
this.getChildByName("OB").mouseEnabled = false
this.getChildByName("OB").mouseChildren = false;
removeEventListener(Event.ADDED_TO_STAGE, added);
addEventListener(MouseEvent.MOUSE_UP, NEXT);
}
如果这不起作用,可能您的代码中还有其他问题,您应该解释并显示您的代码。