看起来这是 ROLL_OVER 的限制或设计特性,请检查以下程序,我已将 ROLL_OVER 事件更改为 MOUSE_OVER,并且 target 和 currentTarget 给出了正确的精灵:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var sParent:Sprite = new Sprite();
var obj:Sprite = new Sprite();
var childA:Sprite = new Sprite();
childA.graphics.beginFill(0xff0000);
childA.graphics.drawRect(0, 0, 100, 50);
childA.graphics.endFill();
var childB:Sprite = new Sprite();
childB.x = 150;
childB.graphics.beginFill(0x00ff00);
childB.graphics.drawRect(0, 0, 100, 50);
childB.graphics.endFill();
sParent.addChild(obj);
obj.addChild(childA);
obj.addChild(childB);
childB.mouseChildren = false;
childB.mouseEnabled = false;
sParent.mouseEnabled = false;
obj.mouseEnabled = false;
sParent.addEventListener(MouseEvent.CLICK, itemClickHandler);
sParent.addEventListener(MouseEvent.MOUSE_OVER, onHoverIn);
sParent.addEventListener(MouseEvent.MOUSE_OUT, onHoverOut);
addChild(sParent);
}
private function onHoverOut(e:MouseEvent):void
{
trace(e.currentTarget.name+ " "+e.target.name);
}
private function onHoverIn(e:MouseEvent):void
{
trace(e.currentTarget.name+ " "+e.target.name);
}
private function itemClickHandler(e:MouseEvent):void
{
trace(e.currentTarget.name+ " "+e.target.name);
}
}
}