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.

12 Responses to “Difference between MouseEvent.ROLL_OVER and MouseEvent.MOUSE_OVER in AS3”

  1. ask Says:

    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.

  2. Janosch Says:

    thanks!

  3. Gary Says:

    Nice! thanks for the explanation, now send it to Adobe for their, seriously lacking, docs.

  4. Ronald Says:

    Ok cool, I was wondering about this.

    btw, lol @ gary

  5. Event’ai (PART I ) at ifmi Says:

    […] jų skirtumus yra labai paprastai ir gražiai paaiškinta čia. Pridedu ir […]

  6. Bruce Says:

    Agrrr, finally somebody explains this. Thanks you saved the day.

  7. [Actionscript 3] sound on mouse roll_over - Forum Flash CS3 Says:

    […] 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 ! […]

  8. TePig Says:

    It’s a cool and great example !

  9. Paul Says:

    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 ;)

  10. gruDEV » Blog Archive » Difference between MouseEvent.ROLL_OVER and MouseEvent.MOUSE_OVER in AS3 Says:

    […] попаднах на един плезен пост в zedia flash blog в които се описва разликата между двата евента, аз […]

  11. Howie Says:

    Great example. I was in the same boat as Paul and headed down that same path. Whew! You just saved me. Thanks.

  12. kj Says:

    brilliant!

    that helps alot!!

    :)

Leave a Reply


Close
E-mail It