I am having a hard time passing a variable to a function as a reference. Here is the part of my code which is the troublemaker:
onMouseDown = function ():Void
{
mouseListener(openCategory, [control[current]]);
};
function mouseListener(callback:Function, callbackParams:Array):Void
{
for (var index in categories)
{
var category:MovieClip = categories[index];
if (category.hitTest(root._xmouse, root._ymouse))
{
control[current] = category;
callback.apply(null, callbackParams);
}
}
}
Now what I want to happen is that the function stored in callback receives a reference to control[current] or at least the most current value of it. What actually happens is the value of control[current] is passed to mouseListener.
How can I get this functionality to work?
Primitives in AS are never passed by reference, you would need to box it into a complex type and pass the boxed value – these are always passed by reference. In your case, pass the entire
control, whatever that is, and readcontrol[current]insidecallback.