You Are Here Home > Cursor hand when mouse over images, Actionscript 3-Flash

Cursor hand when mouse over images, Actionscript 3-Flash

Funny, I couldn’t find the answer to this anywhere, either the answers are unrelated or they are overly complicated. So here is what I did:

         var imageLoader:Loader     = new Loader();
	imageLoader.load(new URLRequest("path to your image/some image.png"));
	var button:Sprite    = new Sprite();
	button.addChild(imageLoader);
	button.buttonMode    = true;
	button.useHandCursor = true;
	addChild(button);

THAT’S IT!!!

UPDATE:
There is a useful comment bellow by Dan and I thought I should include it in this post so it’s easier for everyone to get the info:

Dan:
To get it to work with a Movieclip you need to set the movieclip as button mode true.

If its the entire stage that needs the hand icon you can add to your script layer.

myMc.buttonMode = true;
myMc.useHandCursor = true;

I use it with an Event listener to only use hand cursor on specific movieclips.

myMc.addEventListener(MouseEvent.ROLL_OVER,myMcOver);
 
function myMcOver (e:MouseEvent):void {
   myMc.buttonMode = true;
   myMc.useHandCursor = true;
}
Cursor hand when mouse over images, Actionscript 3-Flash
Filed under: Actionscript, Flash   Posted by: Codehead

Got a Question?

Get answers here.

21 Comments »

  1. Robin:
     

    Thank you! I have been lookinf for this info and there was ANYWHERE ELSE! I think many people want to use the hand cursor in their link images, but it seems no one wants to tell.

    Thanks for sharing this!!

    XOXOOX

    Comment

  2. Codehead:
     

    Hey, thanks, it’s funny, I also feel the same when I search for Actionscript resources, it feels like no one wants to share :)

    Comment

  3. Jeff:
     

    Another way to do this is:

    myBtn.useHandCursor = true;
    myBtn.addEventListener(MouseEvent.MOUSE_UP, myBtnHandler);
    function myBtnHandler(e:Event) {
    trace(“Button Pressed”);
    };

    myBtn is a “Button” under the properties panel. Doesn’t seem to work if it’s a “Movie Clip”. I simply made a square and converted it to a “Button”

    Comment

  4. Noel:
     

    Thanks! Just what I needed.

    Comment

  5.  

    Wow!…
    Almost 1 year to the date and this little bit of code has help tremendously.

    Thanks

    Comment

  6. Codehead:
     

    John, thanks, that is very nice to hear :)

    Comment

  7.  

    Excellent, it was really helpful!

    Comment

  8.  

    You don’t need the line:

    button.useHandCursor = true;

    Comment

  9. Denis:
     

    That is what I needed! Thanks)

    Comment

  10. Dan:
     

    To get it to work with a Movieclip you need to set the movieclip as button mode true.

    If its the entire stage that needs the hand icon you can add to your script layer.

    myMc.buttonMode = true;
    myMc.useHandCursor = true;

    I use it with an Event listener to only use hand cursor on specific movieclips.

    myMc.addEventListener(MouseEvent.ROLL_OVER,myMcOver);

    function myMcOver (e:MouseEvent):void {
    myMc.buttonMode = true;
    myMc.useHandCursor = true;
    }

    Comment

  11. Liz:
     

    YES! I have seriously been looking for this solution for two hours. I had a swf movie that needed to animate on rollover AND make the cursor turn into the pointer hand.

    Perfection, Dan. Sweetness!

    Comment

  12. Johnson:
     

    Thanks, you’re a life saver!

    Comment

  13. dash:
     

    How would you get a hand cursor when using a text element?

    Comment

  14. dan_panagsagan:
     

    you can use the following script if you intend to use it on multiple items.

    myMc1.addEventListener(MouseEvent.MOUSE_OVER, hoverMouseHand);
    myMc2.addEventListener(MouseEvent.MOUSE_OVER, hoverMouseHand);

    function hoverMouseHand(e:Event)
    {
    e.currentTarget.buttonMode = true;
    e.currentTarget.useHandCursor = true;
    }

    Comment

  15. dan_panagsagan:
     

    by that I mean if you want to use it on multiple mc’s without doing a lot of similar functions per mc. :) cheers.

    Comment

  16.  

    Thank you thank you thank you!

    Comment

  17. Benjamin_dk:
     

    I am trying to use the following code in my mouseover eventhandler

    e.currentTarget.buttonMode = true;
    e.currentTarget.useHandCursor = true;

    But I get the error message

    ReferenceError: Error #1056: Cannot create property useHandCursor on flash.display.Loader.
    at core::HeadMenu/headOverListener()
    14
    ReferenceError: Error #1056: Cannot create property useHandCursor on flash.display.Loader.
    at core::HeadMenu/headOverListener()

    I have a hunch that I should do some typecasting, but my first attempt failed

    var e_mc = MovieClip(e);
    e_mc.currentTarget.buttonMode = true;
    e_mc.currentTarget.useHandCursor = true;

    TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@4b3e661 to flash.display.MovieClip.

    I am not sure how to do it. Any help is greatly appreciated…

    Comment

  18. jim:
     

    Hi guys looked at the code above but not sure which part to use.

    at the moment i have this code:

    but i get no mouse over with the hand symbol where should i insert the text that you have created above?

    Comment

  19.  

    p = “people happy with this article”;
    p ++

    =)

    Comment

  20. Anna:
     

    Thank you so much!!! You are genious!

    Comment

  21.  

    Many thanks for this recipe. You saved mea lot of time.

    Comment

RSS feed for comments on this post. TrackBack URL

Leave a comment