# Movieclip runaway from mouse

**URL:** https://forum.kirupa.com/t/movieclip-runaway-from-mouse/328616
**Category:** flash
**Created:** [May 30, 2012, 6:03pm UTC](https://forum.kirupa.com/t/movieclip-runaway-from-mouse/328616 "2012-05-30T18:03:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![vimal32](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@vimal32](https://forum.kirupa.com/u/vimal32)
#### Post date: [May 30, 2012, 6:03pm UTC](https://forum.kirupa.com/t/movieclip-runaway-from-mouse/328616/1 "2012-05-30T18:03:27Z")

</div>

Hi,  
I badly need someone help,Plzzzzzz ☹  
I am new to as3.  
I have converted an As2 code into As3. Am not given any errors when exporting, but the final result is not the same as when I exported the coding in As2.  
Can someone plzz plzz plzzz hlp me,this is for my final year project and am stuck with this part.

```
[U]As3:(What I did)[/U]

  var mc5:redfish5=new redfish5();

    addChild(mc5);
    
    
    
    
    this.x = Math.floor(Math.random()* 550);
    this.y = Math.floor(Math.random()* 400);
    
    
    this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    
    
        this.addEventListener(MouseEvent.CLICK, clickmovie);

    var dy:int; 
    var dx:int;
    var distance:int;
    var angleToMouse:int;
    
    
    var xVel:int;
    var yVel:int;
    
    this.xVel = 0;
    this.yVel = 0;
        

    var xAcc:int;
    var yAcc:int;
    
    
    this.xAcc = 0;
    this.yAcc = 0;    

    function enterFrameHandler(event:Event):void
    { 
    
        
        this.x += this.xVel;
        this.y += this.yVel;
        
        
        
    
        this.xVel += this.xAcc;
        this.yVel += this.yAcc;    

        this.xVel *= 0.95;
        this.yVel *= 0.95;

        if (this.x &gt; stage.width) 
        {
            this.x -= stage.width;
        } else if (this.x &lt; 0) 
        {
            this.x += stage.width;
        }
        if (this.y &gt; stage.height) 
        {
            this.y -= stage.height;
        } else if (this.y &lt; 0) 
        {
            this.y += stage.height;
        }

        calcAcceleration();
    
    
    }

         function calcAcceleration():void
    {
     
        dx = this.mouseX - this.x;
        
        
        dy = this.mouseY - this.y;
        
    
    
        if (Math.abs(dx) &gt; stage.width / 2) 
        {
            if (dx &gt; 0) {
                dx -= stage.width;
            } else {
                dx += stage.width;
            }
        }
        

        
        if (Math.abs(dy) &gt; stage.height/2)
        {
            if (dy &gt; 0) {
                dy -= stage.height;
            } else {
                dy +=stage.height;
            }
        }
        
        
       
        
        
        
        
        angleToMouse= Math.atan2(dy, dx);
        
        
        
        distance = Math.sqrt(dx * dx + dy * dy);
        
        
        
        
        
        this.xAcc = -100 * Math.cos(angleToMouse)/distance;
        this.yAcc = -100 * Math.sin(angleToMouse)/distance;    
    }

```

function clickmovie(e:Event):void{  
trace(“Mouse Click”);  
}

As2 Code:

var mc5 = \_root.attachMovie(“redfish5”, “p”+\_root.getNextHighestDepth(), \_root.getNextHighestDepth());

```
    mc5._x = random(Stage.width);
    mc5._y = random(Stage.height);
    
    mc5.xVel = 0;
    mc5.yVel = 0;
    
    mc5.xAcc = 0;
    mc5.yAcc = 0;
    
    mc5.onEnterFrame = function() 
    {
        
        this._x += this.xVel;
        this._y += this.yVel;
         
        this.xVel += this.xAcc;
        this.yVel += this.yAcc;
        
        this.xVel *= 0.95;
        this.yVel *= 0.95;

        
        if (this._x &gt; Stage.width) 
        {
            this._x -= Stage.width;
        } else if (this._x &lt; 0) 
        {
            this._x += Stage.width;
        }
        if (this._y &gt; Stage.height) 
        {
            this._y -= Stage.height;
        } else if (this._y &lt; 0) 
        {
            this._y += Stage.height;
        }

        
        this.calcAcceleration();
    }
    mc5.calcAcceleration = function()
    {
        
        var dx = _root._xmouse - this._x;
        
        var dy = _root._ymouse - this._y;
        
        
        if (Math.abs(dx) &gt; Stage.width/2) 
        {
            if (dx &gt; 0) {
                dx -= Stage.width;
            } else {
                dx += Stage.width;
            }
        }
        if (Math.abs(dy) &gt; Stage.height/2)
        {
            if (dy &gt; 0) {
                dy -= Stage.height;
            } else {
                dy += Stage.height;
            }
        }
        
        
        var angleToMouse = Math.atan2(dy, dx);
        
        var distance = Math.sqrt(dx*dx + dy*dy);
        
        this.xAcc = -100 * Math.cos(angleToMouse)/distance;
        this.yAcc = -100 * Math.sin(angleToMouse)/distance;        
    }

```

Plzzz help.  
God Bless,thnxs…
