myClip_mc.buttonMode = true;That's kind of a drag if you have already created a movie with dozens (or more!) of clickable MovieClip instances. I'd done just that so I was hoping I was missing some global way getting back this functionality easily. There wasn't... so I made one :)
myClip_mc.useHandCursor = true;
Below is a class that extends from MovieClip, and in its constructor it sets the two properties I'm looking to be set:
package {So all I had to do was go into my library and set the Base Class of each of the Symbols I knew I wanted clickable in my movie. One weird thing I found: after typing that in to the base class field, I needed to click the check mark next to it, it you just clicked "OK" then it'd give you an error.
import flash.display.MovieClip;
class ClickableMovieClip extends MovieClip {
function ClickableMovieClip():void {
this.buttonMode = true;
this.useHandCursor = true;
}
}
}
Not sure why, but I kept thinking it would have been a property of Mouse, but it wasn't this. Helped. Thank you. Simple fix, but searching it, I couldn't come up with the right terms.
ReplyDeleteGreat, I'm glad the blog helped! :)
ReplyDeleteIf you have text in the movieclip you have to add buttonName.mouseChildren = false; This will allows anything contained in the main movieclip to allow the hand cursor as well.
ReplyDeleteDisabling the mouseChildren is a good solution if you only want that symbol instance to be getting the mouse events as a whole, but might cause you trouble if you wanted the items within the symbol getting mouse events. That will prevent the TextField from getting mouse events. For example, if you had it as selectable text, it no longer will be selectable. Or if it was an input field, you won't be able to click in it anymore.
ReplyDeleteThanks!!! This was driving me crazy and my button has text, and even the adobe site doesn't tell you to add .mouseChildren = false;
ReplyDeleteThanks! I was searching this tip. :)
ReplyDeleteAwesome! I'd been adding "myClip_mc.useHandCursor = true" and it still wasn't working, didn't realise I needed to add "myClip_mc.buttonMode = true" as well. Thanks!
ReplyDeleteSmall correction: mc.useHandCursor defaults to true, so really you only need the mc.buttonMode=true line.
ReplyDeleteThe useHandCursor property only exists in case you want mc.buttonMode=true with mc.useHandCursor=false.
David, you are correct in that the useHandCursor property defaults to true. But in order to successfully see the hand cursor, both useHandCursor and buttonMode must have the value of true. Just setting buttonMode alone to true won't do it, nor will just setting useHandCursor. Since my example is in the constructor which subclasses MovieCip, I could have relied on the default value and only set buttonMode. But since my intent was to insure the display of it, setting both values to true is a safe way to go to clearly show my intent in the code and prevent breaking it later (like if I changed it later to extend from another class that messed with the useHandCursor property).
ReplyDeleteJohn. Thank you so much for this very useful tip!
ReplyDeleteThanks
ReplyDelete