AS3 Event Troubleshooting

February 14, 2008

Alright to kick this off I will warn you; I’m a terrible writer. That being said let me get down to what this post is really about, the AS3 MOUSE_LEAVE event. Generally the syntax to add and use an event would be as follows:

stage.addEventListener(MouseEvent.MOUSE_LEAVE, someFunction);

function(event:MouseEvent):void
{
trace(“Your mom goes to college”);
}

Because MOUSE_LEAVE is an event using the mouse it would then belong to the flash.events.MouseEvent. That is also stated in the AS3 Documentation. This is incorrect, however, there is a simple fix – call the event from the class it is actually in… Not what it should be in. You would do it like so:

stage.addEventListener(Event.MOUSE_LEAVE, someFunction);

function(event:Event):void
{
trace(“Your mom goes to college”);
}

Notice the removal of “Mouse”. Interestingly enough when testing your SWF Flash Environment it won’t work. Don’t fret it will work beautifully when actually opened in the Adobe Flash Player.