views:

42

answers:

1

I have wrote a function like ,

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" />

getting error: 1151: A conflict exists with definition obj_inst1 in namespace internal.

+2  A: 
var obj_inst1:Array = obj_inst.selectedItems;

This declares obj_inst1 as an Array

for each(var obj_inst1:Object in obj_inst1)

This tries to redeclare obj_inst1 as an Object - naturally the compiler is confused. Use a different identifier for the iterating variable.

ActionScript Compiler wouldn't complain if you try to redeclare a local variable with the same type as it was declared in the first place (though I can't think of a valid reason to do this).

Also, though it doesn't contribute to this error, there is another obj_inst1 variable of type HPList in your code; it is not a good practice to name everything obj_inst et al. Consider using names that are more meaningful in your application context.

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

Which of the following sounds better?

obj_inst1.function1(obj_inst2.var3);
//or
employees.addItem(dept.head);
Amarghosh
Thanks Amar, itis resolved.
Ravi K Chowdary