At 5/23/12 10:59 AM, dylan-double-c wrote:
this._x -= 3;
this._x += 3;
My three MovieClips are a moving character, a stationary circle (instance name: spike) and a rectangle with 100 frames of decreasing horizontal size (instanced: health).
The plan is to have "health" move closer to the hundredth frame when the first two clips touch.
However, when my first two clips touch, Flash freezes, and later has a window telling me the script is screwing things up.
So I have two questions. Most importantly, what is wrong in my script? It's not doing the intended job.
Secondarily, why does this crash Flash?
A while loop continues until it's broken, or if the condition is no longer met. When neither of these occur, you've caused an infinite loop which will eventually crash the player.
Imagine the scenario where your spike movieclip collides with the other movieclip, the while loop will continue forever until you stop the that condition. How is the condition stopped? The loop is occurring but there's nothing inside the loop to stop it from meeting the condition.
var i = 0;
while(i < 100)
This loop will continue adding to i until it reaches 100, and then after that, the condition isn't true anymore and the while loop stops. However,
var i = 0;
while(i > 0)
In this example, i will always be over 0, so the loop will continue indefinitely and therefore cause it to crash.
Long post short, you need to use an if statement, break your loop or stop meeting the loops condition for it to not crash.