# Sliding bar with buttons

**URL:** <https://forum.kirupa.com/t/sliding-bar-with-buttons/204809>\
**Category:** flash\
**Created:** [October 23, 2006, 6:39pm UTC](https://forum.kirupa.com/t/sliding-bar-with-buttons/204809 "2006-10-23T18:39:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coop](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@coop](https://forum.kirupa.com/u/coop)\
**Post date:** [October 23, 2006, 6:39pm UTC](https://forum.kirupa.com/t/sliding-bar-with-buttons/204809/1 "2006-10-23T18:39:12Z")

</div>

Hi all,

I want a sliding bar to move to a certain point according to which btn is pressed.  
So if you presss the green btn the bar will slide so the green part is on the stage. And then slide straight to the orange if the orange btn is pressed  
I did this code but it only works one way, I’m sure it cos of the += ,but I carn’t see how to alter it so it will slide both ways

[AS]  
slide = function (trag) {  
bar\_mc.onEnterFrame = function() {  
this.\_y += (targ-this.\_y)/2.5;  
if (this.\_y \>= trag) {  
this.\_y = trag;  
this.onEnterFrame = null;  
}  
};  
};  
one\_btn.onRelease = function() {  
slide(0);  
};  
two\_btn.onRelease = function() {  
slide(-400);  
};  
three\_btn.onRelease = function() {  
slide(-800);  
};

[/AS]

---

<div class="post-metadata">

**Author:** ![rhamej](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@rhamej](https://forum.kirupa.com/u/rhamej)\
**Post date:** [October 24, 2006, 2:30am UTC](https://forum.kirupa.com/t/sliding-bar-with-buttons/204809/2 "2006-10-24T02:30:49Z")

</div>

You have some typos. Also, dont you want it to be on the X-axis, not Y? :huh:

```auto

slide = function (trag) {
    this.onEnterFrame = function() {
        bar_mc._x += (trag-bar_mc._x)/2.5;
        if (Math.abs(bar_mc._x-trag)<1) {
            trace('im there');
            bar_mc._x = trag;
            delete this.onEnterFrame;
        }
    };
};
one_btn.onRelease = function() {
    slide(0);
};
two_btn.onRelease = function() {
    slide(-400);
};
three_btn.onRelease = function() {
    slide(-800);
};

```

---

<div class="post-metadata">

**Author:** ![coop](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@coop](https://forum.kirupa.com/u/coop)\
**Post date:** [October 24, 2006, 3:29pm UTC](https://forum.kirupa.com/t/sliding-bar-with-buttons/204809/3 "2006-10-24T15:29:06Z")

</div>

I was rushing typing so that’s the typos, my actual script is with .\_y but the diagram was like that for space.

Thanks, it works great.

---

<div class="post-metadata">

**Author:** ![rhamej](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@rhamej](https://forum.kirupa.com/u/rhamej)\
**Post date:** [October 24, 2006, 5:12pm UTC](https://forum.kirupa.com/t/sliding-bar-with-buttons/204809/4 "2006-10-24T17:12:41Z")

</div>

:thumb:
