MovieClip transparency to mouse click

Before ActionScript 3 came, when you had a MovieClip over a button, if that MovieClip didn’t have any mouse function (onRelease, onRollOver, etc) you could interact with the button underneath. Most of the time this was an unwanted behavior that you had to circumvent by putting an invisible button in your MovieClip and use the useHandCursor =  false line of code.

Well in Flash 9, it doesn’t work that way anymore, if you have a displayObject in front of a button (or displayObject with mouseEvent listeners), it will block the mouse events from happening. That’s really nice in most cases, you don’t have to do the invisible button anymore. But in the project that I just released I had these PNGs with a lot of transparency, so you could see the button underneath. The thing is that you couldn’t interact with the button because of what I just explained earlier. I looked the documentation a bit and I found this property of the DisplayObject: mouseEnabled which is useful in these situations. When you set mouseEnabled to false, your MovieClip, Sprite, DisplayObject will be transparent to mouse events like clicks, rollOvers etc. That way button that are under the DisplayObject with mouseEnabled=false can still work.

Another neat thing with that is that DisplayObject inside the DisplayObject with mouseEnabled=false can still have mouse events. So it’s pretty customizable and useful.

,

  1. #1 by Sean - April 20th, 2008 at 05:01

    Thanks man!

  2. #2 by felix - April 23rd, 2008 at 15:48

    Note setting ‘mouseEnabled’ to false doesn’t work for nested movieclips. To make nested mcs mouse transparent set the parent mc’s ‘mouseChildren’ to false.

  3. #3 by K9 - May 6th, 2008 at 09:47

    Well,
    first let me say that should this work for me, once I have tried it, I will be one glad person, for I have been looking for a solution to a similar problem.

    My problem has to do with my mostly-transparent-FLEX App blocking all mouse events from reaching the HTML behind it.

    Do you think that this will work for me aswell?

  4. #4 by dgelineau - May 6th, 2008 at 22:14

    I don’t know if it will solve your problem, but it sure is worth the try. That’s the first thing I would do.

  5. #5 by Ryan - May 23rd, 2008 at 14:35

    Nice.. I was about the come up with a crazy scheme to get around my issue, but this worked like a charm.

  6. #6 by de - August 1st, 2008 at 07:42

    Thanks man!

  7. #7 by Tunç Atakan - September 14th, 2008 at 08:55

    Perfect. You saves my hours… Thanx…

  8. #8 by Victor - September 16th, 2008 at 19:23

    please help!!, i have i big movie clip that is showing some photos on movment and have his own rolover and out codes for stop and play, each photo its a movie clip wiht buttons, in the main scene in front of all the big mc i have a movie clip that shows the photo in big size, but when i mouse over it work but only in the sides that the mc its not hinder but when im in the middle were is the movie clip it dosent work it get disturbes i dont know whats happen, did i use visible = false codes? hope you can help me.
    here its the code,,, i use your code but i dont know if its ok.

    thank you for your time
    regards.

    DisplayObject: mouseEnabled = false

    slides_mc.slide_mc.NuevoMov_mc.addEventListener(MouseEvent.ROLL_OVER, rolover);
    slides_mc.slide_mc.NuevoMov_mc.addEventListener(MouseEvent.ROLL_OUT, rollout);

    function rolover(gunoi:MouseEvent):void {
    NuevoMov_mc.removeEventListener(Event.ENTER_FRAME,rewind);
    NuevoMov_mc.gotoAndPlay(2);
    }
    function rollout(goz:MouseEvent):void {
    NuevoMov_mc.addEventListener(Event.ENTER_FRAME, rewind);
    }
    function rewind(rewinds:Event):void {
    NuevoMov_mc.prevFrame();
    }

  9. #9 by Freddy - December 10th, 2008 at 02:02

    I placed a dynamic textfield inside a movie clip with mouse events, of course as soon as you pass the mouse over the text the hand cursor just disappears…

    my_mc.my_textfield.mouseEnabled=false just saved the day, thanks a lot!!!

    btw. this was the only reference to this sort of problem I could find online.

  10. #10 by Agent X - February 6th, 2009 at 18:52

    One small correction: it’s actually InteractiveObject:mouseEnabled that does the magic. Interactive Object is a subclass of DisplayObject.

  11. #11 by dreama - March 18th, 2009 at 09:44

    Thanks a lot. We just met the same problem and you get me out.
    God bless you and Google.

  12. #12 by vitaliy - March 19th, 2009 at 18:53

    Thanks man!

  13. #13 by SubtleBreeze - May 15th, 2009 at 05:29

    OMG, you’ve saved so much time and so many braincells. Thank you!

  14. #14 by nick - July 2nd, 2009 at 05:41

    thanks – just what i was looking for!

  15. #15 by Scottx - August 27th, 2009 at 14:37

    Thanks – very simple – but useful.

  16. #16 by Dimitri - November 9th, 2009 at 08:32

    Thanks a million!

    I’ve spend hours trying to fix a simple problem, and this is the sollution! =D

  17. #17 by Lukas - August 20th, 2010 at 17:53

    I was having huge problems with clicking and mouse overs on multiple display object and this trick saved the day. In fact I’m prolly going to refactor all my code to utilize mouseChildren.

  18. #18 by Paulius - September 8th, 2010 at 21:29

    Genius

  19. #19 by dr.noise - November 19th, 2010 at 13:15

    thanks, u da man

  20. #20 by Chuck - December 28th, 2010 at 18:30

    Thank you so much. I just wasted a couple hours on-line (without knowing what words to describe the problem) and in a stack of reference books without results. You’re the best!

  21. #21 by Josh - February 1st, 2011 at 01:10

    @Felix, thanks for the note about mouseChildren, that put me over the top.

  22. #22 by Stewart Matheson - March 30th, 2011 at 02:48

    Yea nice one thanks for this. Just what I was looking for.

  23. #23 by zonabi - March 30th, 2011 at 15:52

    good call. simple thing that can easily be overlooked when transitioning from AS2 to AS3. appreciate your helpful info.

  24. #24 by Jon - April 21st, 2011 at 01:59

    Awesome! I’ve been wondering how to easily solve this problem. Thank You for taking the time to share this.

  25. #25 by Mohon - May 10th, 2011 at 13:42

    That’s really great!!! Saves my lots of time….
    Thanks…..

  26. #26 by berman - June 3rd, 2011 at 10:43

    great, man.
    appreciate this.
    thx a lot.)

  27. #27 by Robakov - June 15th, 2011 at 09:38

    Thanks…..

(will not be published)
Subscribe to comments feed