# Problem with DRAG and ALIGNMENT for "rating bar"

**URL:** <https://forum.kirupa.com/t/problem-with-drag-and-alignment-for-rating-bar/190940>\
**Category:** flash\
**Created:** [June 15, 2006, 9:26pm UTC](https://forum.kirupa.com/t/problem-with-drag-and-alignment-for-rating-bar/190940 "2006-06-15T21:26:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![insomniacl](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@insomniacl](https://forum.kirupa.com/u/insomniacl)\
**Post date:** [June 15, 2006, 9:26pm UTC](https://forum.kirupa.com/t/problem-with-drag-and-alignment-for-rating-bar/190940/1 "2006-06-15T21:26:42Z")

</div>

Hi guys, I was wondering if anyone could help me with this. I’m trying to make a “rating bar”, its basically a slider from 1 to 5. You slide it and it locks into either values 1 2 3 4 5 and then you click RATE and it posts the data.

The problem is, its not sliding properly. I’m trying to use the code from my friend’s file which works perfectly, but for some reason doesn’t on mine.

```auto
on (press) {
 drag = true;
}
on (release, releaseOutside) {
 drag = false;
 lockOn();
 //_root.nextFrame();
}
onClipEvent (load) {
 lockOn = function () {
  if (_x<=posspaces[0]) {
   _x = posspaces[0];
   _root.rating = 1;
  } else if (_x>posspaces[0] && _x<posspaces[1]) {
   if (Math.abs(_x-posspaces[0])>Math.abs(_x-posspaces[1])) {
    _x = posspaces[1];
    _root.rating = 2;
   } else {
    _x = posspaces[0];
    _root.rating = 1;
   }
  } else if (_x>posspaces[1] && _x<posspaces[2]) {
   if (Math.abs(_x-posspaces[1])>Math.abs(_x-posspaces[2])) {
    _x = posspaces[2];
    _root.rating = 3;
   } else {
    _x = posspaces[1];
    _root.rating = 2;
   }
  } else if (_x>posspaces[2] && _x<posspaces[3]) {
   if (Math.abs(_x-posspaces[2])>Math.abs(_x-posspaces[3])) {
    _x = posspaces[3];
    _root.rating = 4;
   } else {
    _x = posspaces[2];
    _root.rating = 3;
   }
  } else if (_x>posspaces[3] && _x<posspaces[4]) {
   if (Math.abs(_x-posspaces[3])>Math.abs(_x-posspaces[4])) {
    _x = posspaces[4];
    _root.rating = 5;
   } else {
    _x = posspaces[3];
    _root.rating = 4;
   }
  } else if (_x>=posspaces[4]) {
   _x = posspaces[4];
   _root.rating = 5;
  }
 };
 _root.rating=3
 i = 0;
 var posspaces:Array = [100, 200, 300, 400, 500];
 Ypoint = 18;
 _y = Ypoint;
 _x = posspaces[2];
}
onClipEvent (enterFrame) {
 if (drag == true) {
  if (_root.mousefinder._x<=posspaces[0]) {
   _x = posspaces[0];
  } else if (_root.mousefinder._x>=posspaces[4]) {
   _x = posspaces[4];
  } else {
   _x = _root._xmouse;
  }
 }
}

```

**[Here](http://easyvideocodes.com/hotness/Slider.swf)** is my friend’s version which works perfectly.  
**[Here](http://easyvideocodes.com/hotness/pinkbar.swf)** is mine which is broken. (I basically copied the symbols and actionscript, I’m terrible at flash)  
If you could help, please let me know. Also, if you have MSN, please PM me or post it, I can always pay a couple bucks for help (and I need flash guys from time to time anyway). Thanks!
