动作接收鼠标事件下编入索引,局部覆盖显示对象? [英] Actionscript Receiving Mouse Events For Lower Indexed And Partially Covered Display Objects?

查看:161
本文介绍了动作接收鼠标事件下编入索引,局部覆盖显示对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个精灵在舞台上。 bottomSprite被添加到显示列表首位,其次是topSprite。 topSprite部分覆盖bottomSprite。

我添加了一个事件侦听器bottomSprite为MouseEvent.MOUSE_MOVED通知简单地跟踪mouseX和mouseY的坐标。然而,该通知不用于bottomSprite的所涵盖topSprite部分工作。

  VAR bottomSprite:雪碧=新的Sprite();
bottomSprite.graphics.beginFill(0x666666,0.5);
bottomSprite.graphics.drawRect(150,150,150,150);
bottomSprite.graphics.endFill();
的addChild(bottomSprite);

VAR topSprite:雪碧=新的Sprite();
topSprite.graphics.beginFill(0x00FFFF,0.5);
topSprite.graphics.drawRect(250,50,150,150);
topSprite.graphics.endFill();
的addChild(topSprite);

bottomSprite.addEventListener(的MouseEvent.MOUSE_MOVE,traceCoords);
功能traceCoords(EVT:MouseEvent)方法:无效
    {
    跟踪(坐标= X:+ bottomSprite.mouseX +,Y:+ bottomSprite.mouseY);
    }
 

解决方案

  topSprite.mouseEnabled = FALSE;
 

注意 topSprite 将不再接收任何鼠标事件。你不能同时两者都接收鼠标事件。因为鼠标移动发生无论是在 bottomSprite 的顶部或 topSprite ,不是他们中的两个 - 他们是兄弟姐妹。

要是 topSprite 一直是一个孩子 bottomSprite ,稍后会收到鼠标事件时,整个前徘徊 - 因为孩子是它的父的一部分。

i have 2 sprites on stage. bottomSprite is added to the display list first, followed by topSprite. topSprite partially covers bottomSprite.

i've added an event listener to bottomSprite for MouseEvent.MOUSE_MOVED notifications to simply trace the mouseX and mouseY coordinates. however, the notification doesn't work for the parts of bottomSprite that are covered by topSprite.

var bottomSprite:Sprite = new Sprite();
bottomSprite.graphics.beginFill(0x666666, 0.5);
bottomSprite.graphics.drawRect(150,150, 150, 150);
bottomSprite.graphics.endFill();
addChild(bottomSprite);

var topSprite:Sprite = new Sprite();
topSprite.graphics.beginFill(0x00FFFF, 0.5);
topSprite.graphics.drawRect(250,50, 150, 150);
topSprite.graphics.endFill();
addChild(topSprite);

bottomSprite.addEventListener(MouseEvent.MOUSE_MOVE, traceCoords);
function traceCoords(evt:MouseEvent):void
    {
    trace ("Coord = X:" + bottomSprite.mouseX + ", Y:" + bottomSprite.mouseY);
    }

解决方案

topSprite.mouseEnabled = false;

Note that the topSprite won't receive any more mouse events. You cannot make both of them receive mouse events simultaneously. Because mouse movement happens either on top of bottomSprite or topSprite, not both of them - they are siblings.

Had topSprite been a child of bottomSprite, later will receive mouse events when you hover across the former - because a child is part of its parent.

这篇关于动作接收鼠标事件下编入索引,局部覆盖显示对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆