2012-09-25 49 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]