Simple counting logic problem

hi guys,

id like to ask for help with my counting logic script. what i want to do is display a set of items by 10, so clicking next_btn shows the next 10 items and also adds 10 items to the start_count var so that the next set starts at the first count (ie 21,31, 41…). counting seems to work fine even if the limit_count var is 54, which shows only 51,52,53,54.

The problem is the backward counting, the operation looks normal but the logic is wrong, when i click the prev_btn the set is repeated (ex. click next appears 1-10, click next again shows 21-30, click prev shows 21-30).

I’ve attached the code below so that you can see what i mean. I think my logic seems wrong somewhere along the code. I tried to play around with the variables but it gets more confusing. Has anyone experienced a similar thing like this before? Any advice you can share would gladly be appreciated.

Thanks a million!
_ScriptRookie


var limit_count = 54;
var start_count = 1;
var end_count = 0;
prev_btn.enabled = false;
prev_btn._alpha = 40;
function nxt(nxtNum) {
 prev_btn.enabled = true;
 prev_btn._alpha = 100;
 end_count += nxtNum;
 if (end_count>=limit_count) {
  end_count = limit_count;
  next_btn.enabled = false;
  next_btn._alpha = 40;
 }
 for (i=start_count; i<=end_count; i++) {
  trace(i);
 }
 start_count += nxtNum;
 if (end_count>=limit_count) {
  start_count -= nxtNum;
 }
 trace("start: "+start_count);
 trace("end: "+end_count);
}
function prv(prvNum) {
 start_count -= prvNum;
 if (start_count<=1) {
  prev_btn.enabled = false;
  prev_btn._alpha = 40;
 }
 for (j=start_count; j<=end_count; j++) {
  trace(j);
 }
 end_count -= prvNum;
 trace("start: "+start_count);
 trace("end: "+end_count);
}
next_btn.onRelease = function() {
 nxt(10);
};
prev_btn.onRelease = function() {
 prv(10);
};