# \[FMX2004\] Problem with -=Prototype=-

**URL:** https://forum.kirupa.com/t/fmx2004-problem-with-prototype/162608
**Category:** flash
**Created:** [September 14, 2005, 6:24pm UTC](https://forum.kirupa.com/t/fmx2004-problem-with-prototype/162608 "2005-09-14T18:24:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![manorius](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@manorius](https://forum.kirupa.com/u/manorius)
#### Post date: [September 14, 2005, 6:24pm UTC](https://forum.kirupa.com/t/fmx2004-problem-with-prototype/162608/1 "2005-09-14T18:24:50Z")

</div>

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

```auto

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)…

```auto

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  
🙂
