Skip to main content
Known Participant
April 15, 2012
Question

How do I get a movie clip to follow the cursor?

  • April 15, 2012
  • 6 replies
  • 3497 views

Hi guys,

What I want:

Is a simple action where I have my company logo in the middle of the screen and it follows the cursor (not over the whole screen but within invisible borders).

What I use:

I have Flash Pro CS5, code is Actionscript 3.0 and my company logo has been converted to a movie clip.

What didn't work:

So I watched 2 different tutorials on how to do this and both didn't work.

With the first one I used this code:

function gradientOver(event:MouseEvent):void{

 

 

          logomc.visible=true;

 

          function reportStageMouse(event:MouseEvent):void{

 

                    var myStageX:Number=Math.round(event.stageX);

                    var myStageY:Number=Math.round(event.stageY);

 

                    var xTween:Tween=new Tween(logomc,"x", Strong.easeOut, logomc.x, myStageX, 1, true);

                    var yTween:Tween=new Tween(logomc,"y", Strong.easeOut, logomc.y, myStageY, 1, true);

          }

          stage.addEventListener(MouseEvent.MOUSE_MOVE,reportStageMouse);

 

}

function gradientOut(event:MouseEvent):void{

          logomc.visible=false;

}

function gradientClick(event:MouseEvent):void{

          logomc.visible=false;

}

gradient.addEventListener(MouseEvent.ROLL_OVER,gradientOver);

gradient.addEventListener(MouseEvent.ROLL_OUT,gradientOut);

gradient.addEventListener(MouseEvent.CLICK,gradientClick);

And with the second one I had to make a border by drawing an oval shape, turn it into a movie clip and put my logo inside of it. Then I used this code:

stage.addEventListener("mouseMove", arjun);

function arjun(e:MouseEvent):void

{

          var var1 = mouseY - followins.y;

          var var2 = mouseX - followins.x;

          var radiusR = Math.atan2(var1,var2);

          var degreeR = radiusR / (Math.PI / 180);

          followins.rotation = degreeR;

}


This topic has been closed for replies.

6 replies

LaurensNLAuthor
Known Participant
April 19, 2012

Got it done!

Here's the tutorial that I watched to get this working:

http://www.youtube.com/watch?v=cw5nIB-7pUY

LaurensNLAuthor
Known Participant
April 17, 2012

Shouldn't be so hard to just get something to follow the cursor slightly.. I've seen tutorials on eyes that do the same and they where short easy tutorials. So I'm just looking for basicly the same technique just modifyed to move my logo instead of an eye and to hide the border only showing my logo.

Anybody have a code for me?

April 15, 2012
LaurensNLAuthor
Known Participant
April 15, 2012

Thanks but this makes a game that also links to somebodys website..

April 15, 2012

...but probably there is a code you need for your purpose

April 15, 2012

Because if the user click with the right mouse button over the swf file, the standard mouse cursor will appear

April 15, 2012

that' s true Ned.......here it is in AS3

logoname.startDrag(true);
Mouse.hide();

logoname.startDrag(true);
Mouse.hide();

stage.addEventListener(MouseEvent.MOUSE_MOVE, hideCursor);
function hideCursor(e:MouseEvent):void{
Mouse.hide();
}

Ned Murphy
Legend
April 15, 2012

IAMDIX - Why did you duplicate two of the lines?  Why did you include the extra code for the listener?  If your solution is what the op is after, then all it needs t be is...

logoname.startDrag(true);
Mouse.hide();

April 15, 2012

ops   didn' t see the duplicate part...no need to duplicate ....

Ned Murphy
Legend
April 15, 2012

What do you mean in terms of the logo following the mouse?  Do you mean that if you move the mouse the logo should tag along and be where the mouse cursor is?  If so,  just use the mouseMove listener and set the log x/y to equal the mouseX/mouseY.

April 15, 2012

On the action of your mc logo use this code....should work  onClipEvent (enterFrame) {  startDrag(this,true);  Mouse.hide()  }

Ned Murphy
Legend
April 15, 2012

IAMDIX - You are offering AS2 code in an AS3 forum... it will not work.