views:

298

answers:

3

What is the equivalent of this AS3 code in AS2?

stage.addEventListener(Event.MOUSE_LEAVE, callbackFunc);

private function callbackFunc(e:Event):void {
    // do something
}
A: 

At first I thought it was just a rollout-

stage.onRollOut = function(){
    //the action could occur here
}

This doesn't seem to be working properly... but then again; you could define the stage as a MovieClip(). AS2 is a bit clunky when it comes to this sort of thing. I think most of the solutions would be hacks. I certainly loved how much simpler it was though. :)

jml
That doesn't work out sadly, because to determine if the mouse is leaving, the MC would need to take up the entire stage...if it takes up the entire stage, the event never fires because when the mouse exits the stage, Flash still only knows of its last position on the stage.
Tegeril
The crux of this problem is revealed in its implementation in AS3, because the STAGE_LEAVE event is on the Event class and not the MouseEvent class.
Tegeril
Sadly, even with the stage handling the event it doesn't work. At least, not for me :P
Tegeril
bummer. yeah; i can see that being the case.
jml
My understanding is that there isn't a direct analogue, and for the implementation I was trying to use this in, we've worked around needing to determine when the mouse leaves, but I'm going to leave this open to see if anyone comes in with a solution for the future.
Tegeril
A: 

You can check _xmouse property to see, if the mouse is not in clip

_root.onMouseMove = function()
{
    if(
       _xmouse <= 0 || 
       _ymouse <= 0 ||
       _xmouse >= Stage.width - 1 ||
       _ymouse >= Stage.height - 1
    )
     outCallBack();
}

function outCallback() { bla; }

This requires that the user click outside of the window, otherwise, when the mouse leaves the stage, it does not update the mouse position beyond the boundary of the player, though this is probably the closest that is attainable with this question.
Tegeril
A: 

There is no equivalent.

Tegeril