I’ve been trying to learn how to use prototypes recently, and I want to make one that resizes a box, with elastic action.
There is a button, and a box movieclip. What I want to happen is when you click the button, a prototype is run to resize the box. But, when I click the button, nothing happens. I feel I’m close, but lost :S
It’s because this.wp and this.w aren’t defined. Therefore you are adding NaN to this._width and this._height which results in no change. Make sure you define your variables before using them. I suppose you mean the arguments w and h by this.w and this.h ? But this.wp, I don’t know.
MovieClip.prototype.spring = function(iw,ih){
var wp = 0;
var hp = 0;
var k = 0.1;
var inertia = 0.9;
this.onEnterFrame = function(){
var w = iw-this._width;
var h = ih-this._height;
wp = wp*inertia+w*k;
hp = hp*inertia+h*k;
this._width += wp;
this._height += hp;
}
}