1

有一个包含许多其他影片剪辑的主容器,在这些 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);
}
4

2 回答 2

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);
}
于 2012-08-01T17:34:34.497 回答
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);    
}

如果这不起作用,则可能您的代码中有其他问题,您应该解释并显示您的代码。

于 2012-08-01T19:52:50.733 回答