Right now the code only have a way to make it bounce on the right wall, which is this part:
if (event.target.x > stage.stageWidth){
event.target.scaleX = -1;
i *= -1;
}
That checks if the X position of the plane is higher than the width of the stage. The X position for the plane at the far left is 0, so to make it switch direction when it goes all the way left, you would need to check if the plane's X position is less than 0.
As Colin mentioned this could be written like this instead:
if (event.target.x > stage.stageWidth || event.target.x < 0){
event.target.scaleX = -1;
i *= -1;
}
This will cause the code to trigger when both the plane is far left and right. "i *= -1" will cause the value of i to switch between negative and positive every time that code is triggered. However, "event.target.scaleX = -1" will only make the plane point to the left every time it is triggered. So that part will need to be updated to this: "event.target.scaleX *= -1"
Another problem with the code is this:
function changeSpeed(event:MouseEvent){
i = 5;
}
Because i should be negative while the plane is flying left, this will cause the plane to fly backwards, if it is flying to the left. While this could be fixed by changing how i is changed, I would recommend using two different variables, one for direction and one for speed. the direction variable would be switch between 1 and -1 depending on the direction, and speed would always be a positive value, that would be increased to make the plane faster.
The movePlane function would then look like this:
function movePlane (event : Event) {
event.target.x += speed * direction;
if (event.target.x > stage.stageWidth || event.target.x < 0) {
direction *= -1;
event.target.scaleX = direction;
}
}