I noticed a comment someone made somewhere (Flashkit I think) about how in the Box2D Flash demo it doesn't detect when the mouse leaves the window (ie keeps trying to pull the mouse joint). Skatehead said he wasn't sure if it was possible and for someone to let him know if they knew how to do it. So here it is:
Obviously you need a function "mouseLeave" or whatever you want to call it to tell it to do whatever. This is only available in AS3 though, so actually until somewhat recently there was no way to do it. I ran into this while creating a custom cursor class and it works very well. One thing I did get hung up on though was that I read about it online and then when I tried to use it I used "MouseEvent.MOUSE_LEAVE" which Flex said didn't exist! I finally realized it is not a MouseEvent (strangely enough since it directly concerns...uh the mouse!). I could see it going either way since it's related to the state of the Flash app, but I really would have gone with MouseEvent... So anyhow that's how it works! I would love to see this used more by people since I'm tired of seeing custom cursors stick on the edge of the window. Also it's nice to deactivate samples on blogs and stuff so it doesn't hog processor.
Code:
addEventListener(Event.MOUSE_LEAVE, mouseLeave);
Obviously you need a function "mouseLeave" or whatever you want to call it to tell it to do whatever. This is only available in AS3 though, so actually until somewhat recently there was no way to do it. I ran into this while creating a custom cursor class and it works very well. One thing I did get hung up on though was that I read about it online and then when I tried to use it I used "MouseEvent.MOUSE_LEAVE" which Flex said didn't exist! I finally realized it is not a MouseEvent (strangely enough since it directly concerns...uh the mouse!). I could see it going either way since it's related to the state of the Flash app, but I really would have gone with MouseEvent... So anyhow that's how it works! I would love to see this used more by people since I'm tired of seeing custom cursors stick on the edge of the window. Also it's nice to deactivate samples on blogs and stuff so it doesn't hog processor.