开发者

different MOUSE_OUT behavior for vertical and horizontal moves?

开发者 https://www.devze.com 2022-12-17 09:24 出处:网络
MOUSE_OUT eve开发者_Go百科nts are, evidently, handled differently for X and Y mouse moves when leaving a Sprite.

MOUSE_OUT eve开发者_Go百科nts are, evidently, handled differently for X and Y mouse moves when leaving a Sprite.

How do I fix this or work around it? Where is this documented?

MOUSE_OUT occurs when x==0, but not y==0 (you need to go to y==-1):

private var _sp:Sprite;

public function test( ):void
{
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;

    _sp = new Sprite( );
    _sp.graphics.beginFill( 0xFF0000, 1 );
    _sp.graphics.drawRect( 0, 0, 15, 15 );
    _sp.graphics.endFill( );
    _sp.x = 10;
    _sp.y = 10;
    _sp.alpha = 1;

    addChild( _sp );

    _sp.addEventListener( MouseEvent.MOUSE_MOVE, msMvCb, false, 0, true );
    _sp.addEventListener( MouseEvent.MOUSE_OUT, msOutCb, false, 0, true );
}

private function msMvCb( evt:MouseEvent ):void
{
    traceMousePos( "mv", evt );
    _sp.alpha = 1;
}

private function msOutCb( evt:MouseEvent ):void
{
    traceMousePos( "out", evt );
    _sp.alpha = .5;
}

private function traceMousePos( note:String, evt:MouseEvent ):void
{
    trace( note + " -- " + evt.localX + ", " + evt.localY + ", " + evt.stageX + ", " + evt.stageY );
}

Here is a trace from moving straight up, with MOUSE_OUT on -1 ...

mv -- 7, 3, 17, 13
mv -- 7, 2, 17, 12
mv -- 7, 1, 17, 11
mv -- 7, 0, 17, 10
out -- 7, -1, 17, 9

And here is a trace from moving straight to the left, with MOUSE_OUT on 0 ...

mv -- 3, 7, 13, 17
mv -- 2, 7, 12, 17
mv -- 1, 7, 11, 17
out -- 0, 7, 10, 17

edit

The same errant behavior occurs with MOUSE_ENTER.


One way to "fix" this behavior is to make a subclass of Sprite which listens to all of its MOUSE_MOVE, MOUSE_OUT, and MOUSE_ENTER events. On examining each event, it should be relatively straightforward to decide whether to let it propagate as normal, stop it entirely, or dispatch a new type of event that matches your desired behavior.

For example, one could listen to MOUSE_MOVE, and if y==0, dispatch a new MOUSE_OUT event (and block any subsequent redundant events if y==-1).


I am no expert, but looks like some bug to me, i tryed with ROLL_OVER too, does the same thing, also as a noticable thing, if you put the box at 0,0 there is a small 1px border on the top of the stage, which also shows as -1 when over it.

0

精彩评论

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