# Make player move towards mouse, not working

**URL:** <https://forum.kirupa.com/t/make-player-move-towards-mouse-not-working/325208>\
**Category:** flash\
**Created:** [October 1, 2011, 4:11pm UTC](https://forum.kirupa.com/t/make-player-move-towards-mouse-not-working/325208 "2011-10-01T16:11:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![blobstah](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@blobstah](https://forum.kirupa.com/u/blobstah)\
**Post date:** [October 1, 2011, 4:11pm UTC](https://forum.kirupa.com/t/make-player-move-towards-mouse-not-working/325208/1 "2011-10-01T16:11:29Z")

</div>

```auto

package {
    
    import enemies.Enemy;
    import flash.display.Sprite;
    import flash.events.*;
    
    public class Main extends Sprite {
        
        // a place to store the enemy
        public var enemy:Enemy;
    
        private function handleEnterFrame(e:Event):void {
            tweenIt(enemy.x, mouseX, 2);
        }
        
        private function tweenIt(variable:Number, target:Number, speed:Number):void{
            if (variable < target) {
                variable += speed;
            }
            
            if (variable > target) {
                variable -= speed;
            }
        }
        
        // this is the first code that is run in our application
        public function Main():void {

            addEventListener(Event.ENTER_FRAME, handleEnterFrame);
            // we create the enemy and store him in our variable
            enemy = new Enemy();
            
            // we add the enemy to the stage 
            addChild(enemy)
            
            enemy.x = Math.random() * stage.stageWidth;
            enemy.y = Math.random() * stage.stageHeight;

        }
        
    }
    
}

```

Here is my main.as. I am using FlashDevelop to program this. Does anyoone have any idea why the Enemy object (which is displayed as a certain sprite) does not move towards the mouse?  
Thank you,  
blobstah
