开发者

e.target detected on CLICK, not on ROLL_OVER

I have a container with several movieclips in. I added an eventlistener to the container and on roll over i trace the e.target.name. The problem is when i roll over the e.target.name is the name of the container, while when i click the e.target.name is the target of the object inside the container. Anyone know how to solve this?

filmsContent.StateBtnContainer.addEv开发者_如何学运维entListener(MouseEvent.ROLL_OVER, stateRollOverHandler);
filmsContent.StateBtnContainer.addEventListener(MouseEvent.CLICK, stateClick);


    private function stateRollOverHandler(e:MouseEvent):void{
        trace(e.target.name);
    }
    private function stateClickHandler(e:MouseEvent):void{
        trace(e.target.name);
    }


Have a look at the differences between target and currentTarget on MouseEvent object. In your code, if you use currentTarget instead of target property you will get in both case get the container object (StateBtnContainer)

Here is a quick example that illustrates the differences :

var container : Sprite = new Sprite();
container.name="container";
container.graphics.beginFill(0xff0000);
container.graphics.drawRect(0, 0, 200, 200);
container.graphics.endFill();
addChild(container);

var child : Sprite = new Sprite();
child.name="child";
child.graphics.beginFill(0x00ff00);
child.graphics.drawRect(50, 50, 100, 100);
child.graphics.endFill();
container.addChild(child);
container.addEventListener(MouseEvent.CLICK, function(e : MouseEvent) : void {
    trace("click",e.target.name);
    trace("click",e.currentTarget.name);
});
container.addEventListener(MouseEvent.ROLL_OVER, function(e : MouseEvent) : void {
    trace("roll over",e.target.name);
    trace("roll over",e.currentTarget.name);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜