moving scripts from object to the main time line

I am trying to move away from attaching script to movie clip instanced or button and put them on the main timeline.
I have created simple flash movie, with 3 buttons left,center,right . They contro the position of a movie clip which is just a picture w 1200 h 200.
when I apply the cript to the button instances it works just fine however the script on the main timeline does not work (some but not desired effect) any idea as to what I am doing wrong
here is the original script
right button:
on (release) {
targetx = 600;
slide.gotoAndPlay("move");
}
center button:
on (release) {
targetx = 200;
slide.gotoAndPlay("move");
}
right button:
on (release) {
targetx = -200;
slide.gotoAndPlay("move");
}

main script
stop();
baseRate =1.6;
difference = _root.targetx-_root.panel._x;
rate = difference/baseRate;
_root.panel._x += rate;


////////
now I replaced the above script with one all present on the main timeline. while the script execute it does not at all move smoothly nor to the exact position it should.
I named the slide clip panel_mc
stop();
function slide(targetx:Number):Void {
      var targetx:Number = targetx;
      var baseRate:Number = 1.6;
      var difference:Number = targetx-panel_mc._x;
      var rate:Number = difference/baseRate;
      panel_mc._x += rate;
}
left_btn.onRelease = function() {
      slide(600);
};
center_btn.onRelease = function() {
      slide(200);
};
right_btn.onRelease = function() {
      slide(-200);
};

DJLUCKYBAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

muso120999Commented:
Just a quick amendment, which can be refined if you like, but this should give you a start:

stop();
function slide(targetx:Number):Void {
      panel_mc.targetx = targetx;
      panel_mc.onEnterFrame = function() {
            var baseRate:Number = 1.6;
            var difference:Number = this.targetx-panel_mc._x;
            var rate:Number = difference/baseRate;
            panel_mc._x += rate;
      };
}
left_btn.onRelease = function() {
      slide(600);
};
center_btn.onRelease = function() {
      slide(200);
};
right_btn.onRelease = function() {
      slide(-200);
};



The key is to get it to update until it's done.

muso
0
muso120999Commented:
Ok, refined it slightly - this one hits the target exactly, and then stops trying to animate further...

function slide(targetx:Number):Void {
      panel_mc.targetx = targetx;
      panel_mc.onEnterFrame = function() {
            var baseRate:Number = 1.6;
            var difference:Number = this.targetx-panel_mc._x;
            var rate:Number = difference/baseRate;
            panel_mc._x += rate;
            if (Math.abs((panel_mc._x - this.targetx))<1) {
                  panel_mc._x = this.targetx;
                  delete this.onEnterFrame;
            }
      };
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.