I have a function and a movieclip prototype. When the prototype applies an onEnterFrame to an mc, it repeatedly calls the function (hitTests for all other mcs). Besides this, it also eases the mc to a new point. However, when the mc have reached this point, the function handling the hitTests stops being called. Why?
// Prototype....
MovieClip.prototype.moveSprite = function(speed, spriteType) {
// Generate random coordinates
var tarX = Math.round(Math.random()*(400-this._width/2)+this._width/2);
var tarY = Math.round(Math.random()*(300-this._width/2)+this._width/2);
this.onEnterFrame = function() {
// Ease to new coordinates
var distX = tarX - this._x;
var distY = tarY - this._y;
this._x += distX/speed;
this._y += distY/speed;
liveLike(spriteType);
}
}
// Function (hitTests were replaced with trace....it does indeed trace until it is halted by the prototype..
liveLike = function(spriteType) {
if(spriteType == "carn") {
trace(spriteType);
} else if(spriteType == "herb") {
//trace(this._name);
} else if(spriteType == "omni") {
//trace(this._name);
}
}
The function should trace “carn” over and over and over, but instead, it traces “carn” over and over until the prototype picks a new point to ease to. Makes no sense to me, can anyone PLEASE help? (This is a class independant study that must be finished in 10 days, lol).