Flex 错误:- 1151:与命名空间内部中的定义 obj_inst1 存在冲突

发布于 2024-09-06 00:16:56 字数 639 浏览 5 评论 0原文

我编写了一个类似的函数,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不疑不惑不回忆 2024-09-13 00:16:56
var obj_inst1:Array = obj_inst.selectedItems;

这将 obj_inst1 声明为 Array

for each(var obj_inst1:Object in obj_inst1)

这试图将 obj_inst1 重新声明为 Object - 编译器自然会感到困惑。对迭代变量使用不同的标识符。

如果您尝试重新声明与最初声明的类型相同的局部变量,ActionScript 编译器不会抱怨(尽管我想不出这样做的有效理由)。

此外,虽然它不会导致此错误,但您的代码中还有另一个 HPList 类型的 obj_inst1 变量;将所有内容命名为 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);
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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文