 # [FMX2004] Problem with -=Prototype=-

Hello everyone,
Can someone please explain to me ,
why this one works (more or less) fine:

``````
var mouseX:Number = new Number();
var mouseY:Number = new Number();
var x:Number = new Number();
var y:Number = new Number();
var xp:Number = new Number();
var yp:Number = new Number();
MovieClip.prototype.elasticMc = function(inertia:Number, k:Number) {
var iniObj:Object = new Object();
iniObj = this;
this.onEnterFrame = function() {
// We calculate the distance to the mouse
x = -iniObj._x+mouseX;
y = -iniObj._y+mouseY;
// We calculate the amount by which the mass will move
xp = (xp*inertia)+(x*k);
yp = (yp*inertia)+(y*k);
// We move it
iniObj._x += xp;
iniObj._y += yp;
updateAfterEvent();
};
this.onMouseDown = function() {
mouseX = _root._xmouse;
mouseY = _root._ymouse;
};
};
this.attachMovie("box", "mcBox2", this.getNextHighestDepth());
var my_color:Color = new Color(mcBox2);
my_color.setRGB(0xff9933);
mcBox2.elasticMc(0.8, 0.5);
mcBox.elasticMc(0.8, 0.5);

``````

But I’m getting trouble with this one(the variables this time, are inside the prototype)…

``````

MovieClip.prototype.elasticMc = function(inertia:Number, k:Number) {
var mouseX:Number = new Number();
var mouseY:Number = new Number();
var x:Number = new Number();
var y:Number = new Number();
var xp:Number = new Number();
var yp:Number = new Number();
var iniObj:Object = new Object();
iniObj = this;
this.onEnterFrame = function() {
// We calculate the distance to the mouse
x = -iniObj._x+mouseX;
y = -iniObj._y+mouseY;
// We calculate the amount by which the mass will move
xp = (xp*inertia)+(x*k);
yp = (yp*inertia)+(y*k);
// We move it
iniObj._x += xp;
iniObj._y += yp;
updateAfterEvent();
};
this.onMouseDown = function() {
mouseX = _root._xmouse;
mouseY = _root._ymouse;
};
};
this.attachMovie("box", "mcBox2", this.getNextHighestDepth());
var my_color:Color = new Color(mcBox2);
my_color.setRGB(0xff9933);
mcBox2.elasticMc(0.8, 0.5);
mcBox.elasticMc(0.8, 0.5);

``````

In addition I noticed that the variables that I’m passing inside the
function (inertia:Number, k:Number) are not unique for every movieClip,
that means that the value that I insert in one movieClip is the value for all movieClips.
How can I use the variables only for the movieclip I’m using?
I thought that when I define the variables inside a movieclip they are local
and they can not be changed from outside.

I’m sure that the answer is obvious but I’m just a beginner…

Thanks 