Sliding bar with buttons

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]

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


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);
};


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.

:thumb: