I am sorry, the problem is not due to the getax function.
It is correct. You do not need to modify it.

The problem is sue to the way you wrote event condition:

[code]
if (v>0) return x+carSize/2-xbumperbottom; // bounced at x=xmax
else if(v<0)return x-carSize/2-xbumpertop; // bounced at x=xmin or x+carSize/2
[/code]
should be changed to

[code]
if (v>0) return xbumperbottom-(x+carSize/2); // bounced at x=xmax
else if(v<0)return xbumpertop-(x-carSize/2); // bounced at x=xmin or x+carSize/2
[/code]

Event occurred only when return value is less than zero.

I also add the following code to pause the simulation.
[code]
if((x+carSize/2)>xbumperbottom+1.e-3){

 x=xbumperbottom-carSize/2;
 v=0;
 _pause();
}
[/code]

The if condition in getax can be removed,too!
Please check out modified version.


By the way:
You can move
[code]
Lmin = -L;
xbumpertop = -L;
[/code]
to [b]on release[/b] event for slider which corresponds to L.

And
[code]
angledeg=angle*180/Math.PI;
[/code]
to [b]on release[/b] event for slider which corresponds to angledegree.