Skip to main content
Known Participant
May 29, 2014
Answered

Custom cursor on roll over

  • May 29, 2014
  • 1 reply
  • 552 views

Hi guys,

I'm trying to get my cursor to change to a custom MovieClip when a certain area is rolled over. My code works but as soon as the rollover is fired the rollout is also fired which creates a loop back and forth the two listeners so the cursor looks like its flickering. I think it may be something to do with the startDrag/stopDrag i have on the custom cursor as i don't get this effect if i remove them. This seems like it should be really straight forward to do but i've tried a few different approaches and keep getting the same effect. What am i missing?

Cheers!

Matt

Code as follows:

var customCursor_mc:CustomCursor = new CustomCursor();


activeArea_mc.addEventListener(MouseEvent.ROLL_OVER, handleEvents);

activeArea_mc.addEventListener(MouseEvent.ROLL_OUT, handleEvents);

activeArea_mc.addEventListener(MouseEvent.CLICK, handleEvents);

function handleEvents(e:MouseEvent):void

{

  switch(e.type)

  {

  case "click":

       trace("clicked");


  break;

  case "rollOver":

       trace("over");

       Mouse.hide();

       customCursor_mc.startDrag(true);

       addChild(customCursor_mc);

  break;

  case "rollOut":

       trace("out");

       Mouse.show();

       customCursor_mc.stopDrag();

       removeChild(customCursor_mc);

  break;

  }

}

This topic has been closed for replies.
Correct answer Amy Blankenship

Hm, that sounds like the cursor itself is causing the problem. Set it to mouseEnabled = false and mouseChildren =  false

1 reply

Amy Blankenship
Legend
May 29, 2014

Add a transparent Shape (i.e. just draw with the Rectangle or Rectangle primitive tool) over everything inside the thing you're rolling over. ROLL_OUT is being triggered because it's rolling over an internal object.

SFMltdAuthor
Known Participant
May 29, 2014

Hi Amy,

Thanks for the reply, i've just tried your solution but it doesn't seem to make any difference. The clip being rolled over is a movieClip with a rectangle primitive inside, this defines a 'hit' area. if i remove the startdrag the rollOut/Over events fire  as expected. Sorry perhaps i've misunderstood what you meant?

Matt

Amy Blankenship
Amy BlankenshipCorrect answer
Legend
May 29, 2014

Hm, that sounds like the cursor itself is causing the problem. Set it to mouseEnabled = false and mouseChildren =  false