for循环(循环变量名)
问题描述:
我有一些变量A1到A14和另一组变量Q1至Q14,而我试图for循环做了这样的for循环(循环变量名)
for(var i:uint = 1; i < 15; i++)
{
if (this("a"+i).x== this("q"+i).x)
{points= points+1 }
else
{
this("q"+i.visible=false;
// shows the good answer
}
}
请帮助:)
答
对象的属性可以通过方括号访问,类似于数组中的索引。 每个属性名称(变量名称)实际上都是一个变量键。 还建议使用Object.hasOwnProptery(propertyName:String)方法检查对象实际上是否具有该属性。
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001424.html
例子:
for(var i:uint = 1; i < 15; i++){
if (this["a"+i].x== this["q"+i].x){
points= points+1;
}
else{
this["q"+i].visible=false;
// shows the good answer
}
}
我没有检查,但它可能是明智的使用而不是单位和toString号码检索创建变量名时,它的字符串值
+1
'uint'在这种情况下罚款(实际上更好)。 –
什么你认为这条线......这个(“q”+ i.visible = false; – Bhavesh