Pass arguments to function

Hi,

I’m having a little problem with how to use the argument sent to a function.

I have this:


_root.onEnterFrame = function() {
  setPanning(1);
}

function setPanning(which) {
  delta_1 = (_root._xmouse) - (_root.mc1._x);
  panning1 = delta_1/8;
  sound1.setPan(panning1);
  _root.pan1 = "panning1 = " + panning1;
}

However, I’d like to change all 1’s in the setPanning function to ‘which’ so I can also use this function for e.g. mc2, mc3 etc.
(Am I making sense?)

However, I don’t know the correct syntax for this.
I tried something like:


"delta_" + which = (_root._xmouse)-("_root.mc" + which + "._x");

but that doesn’t work.

Who can help me??

Thanks,

FlashMataZZ

Ok, I just found out a little more:


delta_1 = (_root._xmouse) - (**_root["mc" + which]**._x);

fixed the right part of this equation.

Now, I’m still stuck with the left part…

Anyone??

Thanks,

FlashMataZZ

I assume you want a delta to be specific for each MC? Then Id suggest keeping it within each mc

_root[“mc”+which].delta = …

Thanks.

I found out that


function setPanning(which) {
  _root["delta_" + which] = (_root._xmouse) - (_root["mc" + which]._x);
...............
}

also does the trick.

Cheers,

FlashMataZZ