0

What is the equivalent of this AS3 code in AS2?

stage.addEventListener(Event.MOUSE_LEAVE, callbackFunc);

private function callbackFunc(e:Event):void {
    // do something
}
David Hall
  • 32,624
  • 10
  • 90
  • 127
Aaron
  • 4,634
  • 1
  • 27
  • 43
  • I've looked around and everyone seems to have relied upon estimating the previous motion of the cursor to determine if it would have left the stage by utilizing an enter frame event, but that is both unreliable and performance impacting. Things like this make me glad I only got into Flash with AS3 :) – Aaron Dec 17 '09 at 17:17

3 Answers3

2

I struggled with this for a while and ended up using JavaScript event listeners on the Flash HTML object and then tying that into Flash's External Interface to set flags for when the mouse over and out events occur. This seems to work perfectly without any bugs.

Ian Smith
  • 36
  • 2
1

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
  • 1,745
  • 6
  • 29
  • 55
  • 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. – Aaron Dec 17 '09 at 17:58
  • 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. – Aaron Dec 17 '09 at 18:00
  • Sadly, even with the stage handling the event it doesn't work. At least, not for me :P – Aaron Dec 17 '09 at 18:23
  • bummer. yeah; i can see that being the case. – jml Dec 17 '09 at 18:33
  • 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. – Aaron Dec 17 '09 at 23:29
1

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;
}
can3p
  • 59
  • 4
  • 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. – Aaron Dec 23 '09 at 15:24