**updated**
Your problem is that container.width
is changed when your shapes fly away from initial rectangle.
If you create a var initialContainerWidth
and save your container width there until you add any shapes to it and then use this saved variable instead of container.width
, it will work fine. Or you can add your flying shapes directly to the stage so that they will not extend container's sizes.
You can just hardcode 1386 instead of container.width to check it.