Dynamic movie clip motion

Running Flash 8

I need to have a movie text containing a dynamically loaded single line text box to move back and forth like a ticker tape. The text box will change content depending which button is pressed, so the length will always change. The effect is something like in the winamp display screen where the text scrolls back and forth depending on the length of the file name.
I can get everything to scroll one way or another but I can’t seem to get it to switch directions when it reaches a certain _X position. I’ve used if statements to set a variable when the _x position reaches a certain point, nested loops, everything I can think of.

These are two versions of the loops I’ve used to move the clip. I’ve tried this in a clipEvent and as a function.

do{
this._x ++;
}while(this._x>300)

do{
j=1/6
scroll_txt = title_txt.length;
this._x = this._x +j;
s++;
} while (s<scroll_txt);

Can anyone help me or at least point me to an example I can look at.

Thanks