我有一个关于Flash错误1151的奇怪问题:内部命名空间中的定义i存在冲突。for循环中的Flash错误1151
这里是有问题的代码:
for(var i:Number=dt.getFullYear(); i >= dt.getFullYear()-90; i--)
{
dtYear.addItem({label:i, data:i});
} //for
//-*-*-* Month
for(var i:Number=0; i < months.length; i++)
{
dtMonth.addItem({label:i, data:i});
} //for
还是比较明显的例子:
for(var i:Number=0; i < 12; i++)
{
trace(i);
} //for
//-*-*-* Month
for(var i:Number=0; i < 12; i++)
{
} //for
的Adobe给出了解释:
You cannot declare more than one variable with the same identifier name within the same scope unless all such variables are declared to be of the same type. In ActionScript 3.0, different code blocks (such as those used in two for loops in the same function definition) are considered to be in the same scope.
该受诅咒这到底是什么?我的意思是i变量一直存在为一个数字,作为一个数字进行了类型化,为什么上面的代码会失败?
如果我以这种方式修改它,它可以工作,但这是UGLY和为什么这是需要的? AAARGGGHHHH ... Flash开发让我发疯。给我一把枪:)。有人向我解释这一个请。
工作代码:
for(var i:Number=dt.getFullYear(); i >= dt.getFullYear()-90; i--)
{
dtYear.addItem({label:i, data:i});
} //for
//-*-*-* Month
for(i=0; i < months.length; i++)
{
dtMonth.addItem({label:i, data:i});
} //for
那么Flash/AS3从来没有一个用户友好的语言/用户界面:)。多么愚蠢的行为:(((。谢谢。 – Jauzsika 2010-07-25 19:31:23