Looking for help with a scripting issue

I posted a similar message on another forum, but didn’t receive any feedback…hopefully somewhere here can help me, as this is driving me crazy!

Here is the code for a slider I’m working on. It’s a 360 pixel slider bar, with 30 marks each 12 pixels apart. If the user releases the dragger in between marks, it should move to the next mark. It will eventually control a panning set of images, so I’m not sure if the way I’m handling this will throw this function off at all.

It only works if you move the slider forward, then back. It’ll then work as it should for a bit, but then it stops working. Can anyone see an error in my script that would cause this to only partially function? (I’ve bolded the parts of the script that control this function).

slider.minX=0;
slider.maxX=360;

slider.onPress=function(){
this.offSet=this._x-_xmouse;
this.active=true;
}
slider.onRelease=function(){
this.active=false;

slider.onEnterFrame=function(){
if(this._x%(this.maxX/30)>0 && this._x<this.maxX){
slider._x+=1;
}

}
updateAfterEvent();
}
slider.onReleaseOutside=function(){
this.active=false;

slider.onEnterFrame=function(){
if(this._x%(this.maxX/30)>0 && this._x<this.maxX){
slider._x+=1;
}

}
updateAfterEvent();
}

slider.onMouseMove=function(){
if(this.active){
this._x=_xmouse+this.offSet;
if(this._x>this.maxX){
this._x=this.maxX;
}
if(this._x<this.minX){
this._x=this.minX;
}

updateAfterEvent();
}
}