Change the speed of a movieClip while it's moving between bountries

I want the user to enter the speed (input text) in which a movieClip is moving back and forth between boundaries and then change it again as the mc is moving.
I’ve managed to make the movieClip start moving whith a certain speed with an onEnterFrame event but when I try to change the speed, it skips the if statements that define the boundaries of the movement and the movieClip exits the scene.
Any help??
Here’s the code so far


 ///code written on movieClip that moves back and forth

onClipEvent(load){
    radious=this._width;
    var speed=0;
    rightWall=_root.range1._x+_root.range1._width; 
    leftWall=_root.range1._x;
}
    onClipEvent(enterFrame){
    if (_root.isOn==true){     //is on gets true with a start button
    speed=0.5*_root.rpm; // where rpm takes values from a text input box
    if(Math.abs(_x-leftWall)<radious){
    
    speed=-speed;
    }
    if(Math.abs(_x-rightWall)<radious){
     speed=-speed;
    }
    
    }
    }