2010-06-16 34 views
0

我已經寫了一個函數一樣,Flex的錯誤: - 1151:衝突與定義obj_inst1存在於命名空間內

private function addSelectedFunc():void 
{ 
    /** 
    * Adds newly selected privilegs to assignedPrivileges 
    */ 
    var obj_inst1:Array = obj_inst.selectedItems; 

    for each(var obj_inst1:Object in obj_inst1) 
     { 
     objInstance1Array.addItem(obj_inste); 
     } 
} 

<ov:HPList id="obj_inst" enabled="true" allowMultipleSelection="true" width="164" height="70" dataProvider="{obj_type.selectedItem}" />  

<ov:HPList id="obj_inst1" enabled="true" allowMultipleSelection="true" width="164" height="70" /> 

收到錯誤:1151: A conflict exists with definition obj_inst1 in namespace internal.

回答

3
var obj_inst1:Array = obj_inst.selectedItems; 

這聲明obj_inst1作爲Array

for each(var obj_inst1:Object in obj_inst1) 

這試圖重新聲明obj_inst1作爲Object - 編譯器自然會感到困惑。爲迭代變量使用不同的標識符。

如果您嘗試重新聲明局部變量的類型與它在第一個地方聲明的類型相同,那麼ActionScript編譯器不會抱怨(儘管我想不出一個合理的原因來做到這一點)。

此外,儘管它不會導致此錯誤,但代碼中還有另一個obj_inst1類型的HPList變量;命名一切obj_inst等都不是一個好習慣。考慮使用在您的應用程序上下文中更有意義的名稱。

//items is again a generic one, you should be able to do better 
var items:Array = obj_inst.selectedItems; 
for each(var item:Object in items) 
{ 
    objInstance1Array.addItem(item); 
} 

以下哪項聽起來比較好?

obj_inst1.function1(obj_inst2.var3); 
//or 
employees.addItem(dept.head); 
+0

謝謝Amar,itis解決了。 – Ravikanth 2010-06-16 09:51:54