# Can you make this code better?

**URL:** <https://forum.kirupa.com/t/can-you-make-this-code-better/198025>\
**Category:** flash\
**Created:** [August 21, 2006, 9:14pm UTC](https://forum.kirupa.com/t/can-you-make-this-code-better/198025 "2006-08-21T21:14:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecurtis](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@ecurtis](https://forum.kirupa.com/u/ecurtis)\
**Post date:** [August 21, 2006, 9:14pm UTC](https://forum.kirupa.com/t/can-you-make-this-code-better/198025/1 "2006-08-21T21:14:21Z")

</div>

Hi all,

I created an [Infinite menu](http://www.kirupa.com/developer/mx/infinite.htm) item and after reading through the forums I applied a few tweaks to get the follow behaviors:

a) only rolls when the mouse is over the MC  
b) has a deadzone of about 200 pixels in the center for easy clicking

One problem i am having is that it will stop scrolling if I leave the swf above or below it, however sometimes it continues scrolling if I leave by the left or right edge.

I am also curious if this could be simplified.

```auto
onClipEvent (load) { 
    xcenterhigh = 442; 
    xcenterlow = 250; 
    speed = 1/20; 
} 

onClipEvent (enterFrame) { 
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
	
	if (_root._xmouse>xcenterhigh) { 
        var distance = _root._xmouse-xcenterhigh; 
        
    } else if (_root._xmouse<xcenterlow) { 
        var distance = _root._xmouse-xcenterlow; 
		
    } else if (_root._xmouse>xcenterlow) { 
        if (_root._xmouse<xcenterhigh) { 
        var distance = 0; 
    } 
    } 

	_x += (distance*speed); 
        if (_x>0) { 
            _x = -692; 
        } 
        if (_x<-692) { 
            _x = 0; 
        } 
} }

```

Thanks,

Eric
