闪光AS3 - 我怎么找对象的索引数组 [英] flash as3 - how do I find an object's index in an array
问题描述
你如何找到Flash ActionScript中3阵列中的一个对象的索引/持何立场?我想设置条件在一个循环的地方,如果一个对象的ID等于current_item变量,我可以在阵列内返回它的位置。
how do you find an object's index / position within an array in flash actionscript 3? I am trying to set a conditional up in a loop where, if an object's id is equal to the current_item variable, I can return its position within the array.
推荐答案
这样的事情可能会帮助你 - 这个例子返回的位置值7:
Something like this might help you - this example returns the position of the value 7:
private var _testArray:Array = new Array(5, 6, 7, 8, 9, 8, 7, 6);
public function ArrayTest()
{
trace (_testArray.indexOf(7));
//Should output 2
}
所以你的需求:
so for your needs:
item variableToLookFor = 9 // Your variable here
private var _testArray:Array = new Array(5, 6, 7, 8, 9, 8, 7, 6);
public function ArrayTest()
{
trace (_testArray.indexOf(variableToLookFor));
//Should output 4
}
这将返回-1,如果您的项目不存在,否则将输出数组中的位置。
This will return a -1 if your item doesn't exist, otherwise it will output the position in the array.
如果您需要了解更多信息,您可以检查此处在AS3数组的文章。
If you need more information you can check here for an article on AS3 Arrays.
这篇关于闪光AS3 - 我怎么找对象的索引数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!