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:与命名空间内部中的定义 obj_inst1 存在冲突。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将
obj_inst1
声明为Array
这试图将
obj_inst1
重新声明为Object
- 编译器自然会感到困惑。对迭代变量使用不同的标识符。如果您尝试重新声明与最初声明的类型相同的局部变量,ActionScript 编译器不会抱怨(尽管我想不出这样做的有效理由)。
此外,虽然它不会导致此错误,但您的代码中还有另一个
HPList
类型的obj_inst1
变量;将所有内容命名为 obj_inst 等并不是一个好习惯。考虑使用在您的应用程序上下文中更有意义的名称。以下哪一个听起来更好?
This declares
obj_inst1
as anArray
This tries to redeclare
obj_inst1
as anObject
- 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 typeHPList
in your code; it is not a good practice to name everythingobj_inst
et al. Consider using names that are more meaningful in your application context.Which of the following sounds better?