Flash Q: setInterval()
- Started
- Last post
- 5 Responses
- CyBrainX
I copied this from Colin Moock's O'Reilly book and put it on frame 1, so I thought it would work. I added the if statement with clearInterval, but the first part doesn't work. I'm just trying to get a simple use out of this, but anywhere else I try to read up on this, the more confusing and ridiculous it seems. Any help?
moveBall = function () {
this.ball._x += 10;
}
ballMoverID = setInterval(moveBall, 20);
trace(ballMoverID);
if (ballMoverID >= Stage.width-this._width) {
clearInterval(ballMoverID);
trace("cleared");
}
- unfittoprint0
u should put the if statement inside the moveball function:
moveBall = function () {
this.ball._x += 10;
if (this.ball._x >= Stage.width-this._width) {
clearInterval(ballMoverID);
trace("cleared");
}
}ballMoverID = setInterval(moveBall , 20);
trace(ballMoverID);
- CyBrainX0
That makes sense, but I'm not up to the clearInterval() part yet. The function won't move the ball.
Thanks for the tip though.
- Mick0
You gave your ball the instance name "ball"?
- CyBrainX0
Yes, a nice little circle with an instance name ball is the only thing on the stage with one frame that has that script on it. I'm outputting Flash 6
Maybe Flash is broken.
- autonoma0
moveBall = function () {
ball._x += 10;
if (ball._x >= Stage.width - ball._width) {
clearInterval(ballMoverID);
trace("cleared");
}
}ballMoverID = setInterval(moveBall , 20);