# AS2 Need help with script for checking mousedirection

**URL:** https://forum.kirupa.com/t/as2-need-help-with-script-for-checking-mousedirection/296961
**Category:** flash
**Created:** [September 23, 2009, 12:18pm UTC](https://forum.kirupa.com/t/as2-need-help-with-script-for-checking-mousedirection/296961 "2009-09-23T12:18:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![adBuryD](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@adBuryD](https://forum.kirupa.com/u/adBuryD)
#### Post date: [September 23, 2009, 12:18pm UTC](https://forum.kirupa.com/t/as2-need-help-with-script-for-checking-mousedirection/296961/1 "2009-09-23T12:18:20Z")

</div>

hi,  
I would like to know how to perform a chek on the direction of the movement of the mouse on stage like let us say considering the stage.height/2 as the center if the mouse moves up it should trace up and down if it moves down…  
I did it by storing all the \_ymouse coordinates in temp array and chking if temp\*\>temp[i-1]  
but it doesn’t work satisfactorily … would appreciate some help… i am posting the script i made…i do admit i am very bad in calculations so correct me if i went wrong somewhere

```auto

[COLOR=DarkRed]var m = [2, 3, 4, 5];
var temp = [];
var mouselist:Object = new Object();

var centerStg = Stage.height/2;

mouselist.onMouseMove = function() {
    var dist = _ymouse-centerStg;
    _root.dist.text = Math.round(dist);
    temp.push(dist);
    for (k=0; k<temp.length; k++) {
        if (temp[k]>temp[k-1]) {
            trace("mouseMoveDown");
        } else {
            trace("mouseMoveUp");
        }
    }
};
Mouse.addListener(mouselist);
[/COLOR]

```
