Difference between MouseEvent.ROLL_OVER and MouseEvent.MOUSE_OVER in AS3
This was a question that has been in my head for a long time: what is the difference between MouseEvent.ROLL_OVER and MouseEvent.MOUSE_OVER. I have been using MouseEvent.MOUSE_OVER for all my rollOvers up to now without really thinking about it, but I think it would be interesting to know the difference for something so basic.
If you look at the documentation that comes with Flash CS3. You will find very little help. There are no examples explaining the difference between the two. The only difference you will find there is that the MOUSE_OVER event has the bubbles property set to true and the ROLL_OVER to false. I don’t know how much that property impacts on the behavior of the event, but I am keeping event bubbling for another post (I have been postponing that post for a long time).
Where I found there was a difference between the two events is in the way they handle children of the display object you added the listener too. I have made a simple example to show this:
In that flash example, be sure to roll over the blue part of the button to really see the difference(note that the blue rectangle is inside the black rectangle movieClip, not just over). In the MOUSE_OVER example, the event is fired for every children of the display object that the listener was added to. This does not happen with the ROLL_OVER event. If you move your mouse from the exterior of the button to the blue part MOUSE_OVER will generate 3 times the events that ROLL_OVER will. One way to make MOUSE_OVER act as ROLL_OVER is to set mouseChildren = false but as a consequences: the first is that it will disable all mouse events from children which I think might help the CPU but at the same time you won’t be able to interact with the children with the mouse.
In our previous example, it didn’t really matter how many events where fired because we used a tween to do the rollover and we weren’t able to see the difference visually, but there might be times where you will want all the different events. Like if you want the mouse cursor to change when over a movieClip and still want rollOver effects from children of that movieClip, you would use the MouseEvent.ROLL_OVER to change the mouse cursor and MouseEvent.MOUSE_OVER for the children movieClips rollOver effects.
As a side note on cpu efficiency, it doesn’t really matter if you listen to MouseEvent.ROLL_OVER or MouseEvent.MOUSE_OVER events, they are both as efficient. What will save you cpu cycles is if you disable the children of a movieClip from sending events if you don’t need them (even if you don’t listen to them events are still fired) using mouseChildren = false.
I hope this shed some light on the subject.
June 24th, 2008 at 11:20 am
Yep, you just saved me a few hours work for sure. Clear explanation and nice examples. Cheers very much. And good look with the event bubbling post. Ask.
June 30th, 2008 at 10:17 am
thanks!
June 30th, 2008 at 6:30 pm
Nice! thanks for the explanation, now send it to Adobe for their, seriously lacking, docs.
July 29th, 2008 at 3:17 am
Ok cool, I was wondering about this.
btw, lol @ gary
July 31st, 2008 at 4:35 am
[…] jų skirtumus yra labai paprastai ir gražiai paaiškinta čia. Pridedu ir […]
August 14th, 2008 at 9:06 am
Agrrr, finally somebody explains this. Thanks you saved the day.
August 26th, 2008 at 11:13 am
[…] Difference between MouseEvent.ROLL_OVER and MouseEvent.MOUSE_OVER in AS3 | zedia flash blog __________________ I recommend: Essential Actionscript 3.0 - Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum ! - I do not reply technicians pvt messages. Open a thread ! […]
September 17th, 2008 at 10:28 pm
It’s a cool and great example !
September 30th, 2008 at 7:01 am
If only I’d found this post earlier, I wouldn’t have spent the morning banging my head trying to fix an issue related to using MouseEvent.MOUSE_OUT - I was even doing weird stuff with getRect( this ).containsPoint( ) etc. to try and get around it!
Changed it all to ROLL_OVER/ROLL_OUT and it works first time!
Anyway, thanks for the post and examples. You may have just saved my productivity for today
October 1st, 2008 at 10:54 am
[…] попаднах на един плезен пост в zedia flash blog в които се описва разликата между двата евента, аз […]
October 22nd, 2008 at 9:57 am
Great example. I was in the same boat as Paul and headed down that same path. Whew! You just saved me. Thanks.
November 12th, 2008 at 11:51 am
brilliant!
that helps alot!!