2012-09-25 48 views
0

我很难将变量传递给函数作为参考。这里是我的代码的一部分是麻烦制造者:传递变量作为参考

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); 
     } 
    } 
} 

现在我希望发生的是,存储在callback函数接收到control[current],或者至少它的最新值的参考。实际发生的是control[current]的值传递给mouseListener

如何获得此功能?

回答

0

AS中的基元永远不会通过引用传递,您需要将其装入复杂类型并传递装箱值 - 这些值始终通过引用传递。在你的情况下,通过整个control,无论如何,并在callback内读取control[current]