View Full Version : setInterval with prototypes
H4T
November 8th, 2004, 11:16 AM
I have a movieclip prototype which I want to be applied to different movieclips every so often. The prototype controls it's movement, when it runs, the mc eases to a random x and y and stops. After that I want it to keep executing that movement prototype over and over, ie, keep moving around.
I know how to use setInterval with functions, and I know movieclip prototypes basically are functions, but how can I get setInterval to work with movieclip prototypes assigned to specific movieclips?
stringy
November 8th, 2004, 12:26 PM
I have a movieclip prototype which I want to be applied to different movieclips every so often. The prototype controls it's movement, when it runs, the mc eases to a random x and y and stops. After that I want it to keep executing that movement prototype over and over, ie, keep moving around.
I know how to use setInterval with functions, and I know movieclip prototypes basically are functions, but how can I get setInterval to work with movieclip prototypes assigned to specific movieclips?
something like this
MovieClip.prototype.move = function() {
this.targetX = Math.round(Math.random()*Stage.width);
this.targetY = Math.round(Math.random()*Stage.height);
this.onEnterFrame = function() {
this._x += (this.targetX-this._x)/5;
this._y += (this.targetY-this._y)/5;
if (Math.abs(this.targetX-this._x)<1 && Math.abs(this.targetY-this._y)<1) {
delete this.onEnterFrame;
this._x = this.targetX;
this._y = this.targetY;
}
};
};
//mc instance name mc1
myinterval = setInterval(mc1, "move", 3000);
H4T
November 8th, 2004, 06:04 PM
w00t, there's my answer...I didn't think it'd be as simple as that :D. Thanks a bunch, stringy :)
stringy
November 8th, 2004, 07:18 PM
w00t, there's my answer...I didn't think it'd be as simple as that :D. Thanks a bunch, stringy :)
welcome
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.