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 on September 21, 2008

Disclaimer
1 - Use the information provided here at your own risk.
2 - You may not republish this content without prior written consent.




17 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 — June 16, 2009 @ 2:26 pm

  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 — June 16, 2009 @ 3:24 pm

  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 — August 9, 2009 @ 9:47 am

  4. Noel:
     

    Thanks! Just what I needed.

    Comment — August 12, 2009 @ 1:30 pm

  5.  

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

    Thanks

    Comment — September 15, 2009 @ 5:20 pm

  6. Codehead:
     

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

    Comment — September 15, 2009 @ 5:35 pm

  7.  

    Excellent, it was really helpful!

    Comment — September 30, 2009 @ 10:17 am

  8.  

    You don’t need the line:

    button.useHandCursor = true;

    Comment — October 7, 2009 @ 5:33 pm

  9. Denis:
     

    That is what I needed! Thanks)

    Comment — October 22, 2009 @ 1:00 pm

  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 — November 11, 2009 @ 4:48 am

  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 — January 4, 2010 @ 4:36 pm

  12. Johnson:
     

    Thanks, you’re a life saver!

    Comment — January 28, 2010 @ 2:33 pm

  13. dash:
     

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

    Comment — February 16, 2010 @ 5:17 pm

  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 — February 18, 2010 @ 9:46 am

  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 — February 18, 2010 @ 9:51 am

  16.  

    Thank you thank you thank you!

    Comment — February 20, 2010 @ 8:42 pm

  17. 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 — February 26, 2010 @ 8:04 am

RSS feed for comments on this post. TrackBack URL

Leave a comment