# Mouse STAGE Confusion

**URL:** <https://forum.kirupa.com/t/mouse-stage-confusion/255581>\
**Category:** flash\
**Created:** [March 25, 2008, 12:11am UTC](https://forum.kirupa.com/t/mouse-stage-confusion/255581 "2008-03-25T00:11:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnns](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@bnns](https://forum.kirupa.com/u/bnns)\
**Post date:** [March 25, 2008, 12:11am UTC](https://forum.kirupa.com/t/mouse-stage-confusion/255581/1 "2008-03-25T00:11:59Z")

</div>

I am working on a flash application that takes in the mouse’s location on the stage and then gets objects to rotate around it based on its location. The problem is that whenever the mouse moves over one of my objects it sends the objects to the corner of the screen.

I create a new [COLOR=#0000ff]BlueCircle [/COLOR][COLOR=black]from the class i created [/COLOR][COLOR=black]when. the project loads i give each [COLOR=#0000ff]BlueCircle [/COLOR]a referance to the [/COLOR][COLOR=sienna]stage.[/COLOR]

```auto

var aCircles:Object = new Object;
aCircles.number=0;
function DisplayCircles() 
{ 
for (var i:int = 0; i < 10; i++) 
{ 
[COLOR=sienna]var mainStage = this.stage;[/COLOR]
var newCircle:[COLOR=blue]BlueCircle[/COLOR] = new [COLOR=blue]BlueCircle[/COLOR](aCircles.number,[COLOR=sienna]mainStage[/COLOR]); 
//BlueCirlce Contains the Property (nCircle)
 //When the nCircle is Defined the BlueCircle MovieClip is affected
//newCircle.nCircle = aCircles.number;
this.addChild(newCircle); 
 
newCircle.x = Math.random()*150; 
newCircle.y = Math.random()*100; 
newCircle.alpha = .2+Math.random()*.5; 
 
var scale:Number = .3+Math.random()*2; 
newCircle.scaleX = newCircle.scaleY = scale; 
aCircles.number++;
} 
} 
DisplayCircles(); 
trace(aCircles.number);
 

```

The Class BlueCircle is defined below. I add two addlisteners one for the [COLOR=blue]MOUSE\_MOVE [/COLOR][COLOR=black]and one for [/COLOR][COLOR=red]ENTER\_FRAME[/COLOR][COLOR=black]. [COLOR=blue]The MOUSE\_MOVE addlistener is added to the passed in location of the stage from the main timeline. There the mouse’s location is set.[/COLOR] [/COLOR][COLOR=red]On the enter\_frame I update the location of the object to ease toward the location of the of the Current mouse position.[/COLOR]

```auto

package 
{
 import flash.display.MovieClip;
 import flash.events.Event;
 import flash.display.*;
 import flash.text.TextField;
 import flash.events.MouseEvent;
 public class BlueCircle extends MovieClip
 {
  var radians = 0;
  var speed = 0;
  var mspeed = 0;
  var radius = 5;
 
  var nCircle:Number;
 
  var oMouseProp:Object = {locationX:Number,locationY:Number};
 
  public function BlueCircle(aCircle:Number = 0, oMouseLocation:Stage = null)
  {
   speed = .01+.5*Math.random();
   mspeed = speed*100;
   radius = 2+10*Math.random();
 
[COLOR=red] this.addEventListener(Event.ENTER_FRAME, RotateCircle);[/COLOR]
 
[COLOR=blue]if (oMouseLocation!=null)[/COLOR]
[COLOR=blue] {[/COLOR]
[COLOR=blue] oMouseLocation.addEventListener(MouseEvent.MOUSE_MOVE,fCircleMouseFollow);[/COLOR]
[COLOR=blue] }[/COLOR]
 
  }
 
 [COLOR=blue]function fCircleMouseFollow(e:MouseEvent)[/COLOR]
[COLOR=blue] {[/COLOR]
[COLOR=blue] oMouseProp.locationX = e.localX;[/COLOR]
[COLOR=blue] oMouseProp.locationY = e.localY;[/COLOR]
[COLOR=blue] }[/COLOR]
 
 [COLOR=red]function RotateCircle(e:Event)[/COLOR]
[COLOR=red] {[/COLOR]
 
[COLOR=red] radians += speed;[/COLOR]
[COLOR=red] this.rotation += Math.round((Math.PI/180)*radians);[/COLOR]
 
[COLOR=red] if (oMouseProp!=null)[/COLOR]
[COLOR=red] {[/COLOR]
[COLOR=red] this.x+=((oMouseProp.locationX-this.x)/mspeed);[/COLOR]
[COLOR=red] this.y+=((oMouseProp.locationY-this.y)/mspeed);[/COLOR]
[COLOR=red] }[/COLOR]
[COLOR=red] }[/COLOR]
 }
}
 

```

So each time the mouse moves over a [COLOR=blue]BlueCircle [/COLOR][COLOR=black]it [/COLOR][COLOR=black]gets the location from the stage the mouse is over, which is the [COLOR=#0000ff]BlueCircles,[/COLOR] any ideas? How would i get the mouse’s location to stay locked to one object, the main timeline?[/COLOR]
