使用另一个数组作为搜索条件来搜索多维数组 (Flash As3)
长话短说:我想在 AS3 中的多维数组中搜索(在本例中)6 个字符串的位置 - 所有这些字符串都存储在另一个无关的数组中。
长话短说:
一旦我获得每个字符串的位置(在多维数组中),我就知道它的位置,并且可以访问该对象的其他属性 - 所以如果我发现字符串“box3”位于元素 [5 ] 我的多维数组,我现在可以定位:
multiArray[5][3] 返回存储的第四个项目(请记住我们从 0 开始,所以 3 是第四个位置)。
我可以让它工作一次,但我试图根据基本字符串存储数组的长度设置一个 for 循环 - 该数组保存(在本例中)6 个实例名称字符串 - 每次我的 for 循环循环时,我需要在多维数组中搜索下一个连续实例名称。
然后,一旦我找到了所有这些(并将结果存储在一个新的临时数组中),我就可以在每个位置中挖掘我需要的信息。
我唯一能找到的是这里的帖子:
http://exoboy.wordpress.com/2010/07/15/successively-searching-multiDimension-arrays-in-as3/
效果很好,如果我只在数组中搜索一个元素 - 但当我需要使用其代码在 for 循环中查找多个元素时,它就会崩溃。您也可以在该页面上查看我的问题/他们的回复,以获取更多信息。
我最终需要一个简单的运行函数,可以反复重复使用,因为我将在该数组中进行大量搜索以查找我正在构建的模拟。谢谢大家, -埃里克
Long story short: I want to search a multidimensional array in AS3 for (in this example) the location of 6 strings - all of which are stored in another unrelared array.
Long story long:
Once I get the locations (in the multidimensional array) of each string, i then know where it's located, and can access other atributes of that object - so if i found the string "box3" is located in element [5] of my multidimensional array, i can now target:
multiArray[5][3] to return the 4th item stored (keeping in mind we're starting from 0, so 3 is the 4th position).
I can get this to work once, but I'm trying to set up a for loop based on the length of my basic string storage array - this array holds (in this example) 6 instance name strings - each time my for loop loops, i need to run a search in my multdimensional array for the next consecutive instance name.
Then, once I've located all of them (and store the results in a new temporary array) I can dig around in each location for the info I need.
The only thing I can find is the post here:
http://exoboy.wordpress.com/2010/07/15/successfully-searching-multidimensional-arrays-in-as3/
which works GREAT if I'm only searching for one elements in my array - but soon as I need to find multiple elements in a for loop using their code it falls apart. You can see my question/their response on that page as well for some more info.
I need a simple to run function in the end that can be re-used over and over as I'll be doing a lot of searching in that array for the simulation i'm building. Thanks everyone,
-Eric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你需要两个 for 循环。
使用一个循环在数组中进行搜索(这是您已有的循环代码),并将其包装在另一个执行该搜索循环的 for 循环中。
有道理吗?
I guess you need two for loops then.
use one loop for the searching in the array (that's the loop code you already have), and wrap it in another for loop which executes that searchloop.
Makes sense?
此版本使用方法本身 searchArray() 进行循环,并跟踪树中的位置。一旦找到匹配项,它就会将位置输出到 searchResults。然后,您可以对每个 uint 数组使用 getNestedItem() 来检索值。
This version loops using the method itself, searchArray(), and keeps track of the position in the tree. Once it finds a match, it outputs the position to searchResults. Then you can use getNestedItem() with each array of uints to retrieve the value.
这是您可以使用的基本函数。
显然,您需要循环调用此函数的所有数组进行测试。
Here is the base function you could use.
Obviously you will need to loop all your arrays calling this function for the test.