When your AIH reaches stage.stageHeight, the following happens:
- Y is assigned stage.stageHeight (==AIH)
- AIH is incremented by 3*AIHS (==3, assuming AIHS==1, although the actual value of AIHS doesn't matter, only its sign does). Therefore your paddle actually moves 3 pixels more than you want.
- You check the condition, it's true, so AIHS=-1*AIHS. AIHS is now -3.
- Okay, next frame, Y is assigned AIH (==stage.stageHeight+3), AIH is incremented by AIHS, and is now equals stage.stageHeight again. Checking condition is false, no change to AIHS. Paddle is now moving upwards.
- Next frame, Y is assigned AIH that equals to stage.stageHeight, but the paddle is now moving upwards! So, when you again check for your condition, AIHS reverts to +3. And, AIH is already stage.stageHeight-3, so 2 frames further the cycle will repeat.
A fix will be to place increment of AIH after you alter AIHS. This is actually the most common cause of errors, you first apply unchanged value, then change it, instead of first changing, then applying.