试图找出一些逻辑并想知道以下代码是否有效,或者是否有其他方法可以做到这一点。 (只是试图找出我的逻辑是否有效,可能会错过一些代码)
Var some1:MovieClip = mc_1;
" "
" "
Var other1:MovieClip = mc_a;
" "
" "
Var myArray = [some1, some2, some3];
Var i:uint;
Var iLength:uint = myArray.length;
For(i=0;i<iLength;i++){
If(myArray[i] == some2){
myArray[i] = other1;
}
}
问题:这会取代&some; some2&#39;与&#39; other1&#39;?
答案 0 :(得分:1)
你的代码应该被编辑:但如果你修复类似的错误,答案是肯定的:
var some1:MovieClip = mc_1;
var other1:MovieClip = mc_a;
var myArray:Array = [some1, some2, some3];
var i:uint;
var iLength:uint = myArray.length;
for(i=0;i<iLength;i++){
if(myArray[i] == some2){
myArray[i] = other1;
break;
}
}
♠方法2
Array.indexOf(Item)会在 Item
中返回 Array
的位置,如果 {{ 1}} 存在,否则返回 Item
-1
♠方法3
使用拼接
删除如果声明var some1:MovieClip = mc_1;
var other1:MovieClip = mc_a;
var myArray:Array = [some1, some2, some3];
if(myArray.indexOf(some1)>=0) myArray[myArray.indexOf(some1)] = other1;