在Flash AS3中查找数组中对象的索引
可能的重复:
flash as3 - 如何找到数组中对象的索引
我有一个类似于以下内容的对象数组:
[
{
start : 0.000,
end : 0.100
},
{
start : 0.100,
end : 0.200
},
{
start : 0.200,
end : 0.300
}
]
是否有一种快速方法可以让我逐帧查询此对象以找出值(在本例中为音频播放的当前时间)谎言?
与我的同事聊天后,他们建议我将其枚举到一个大型索引值数组中,并引用它们所关联的索引,例如
[000] = 0
[001] = 0
...
[100] = 1
...
[200] = 2
Possible Duplicate:
flash as3 - how do I find an object's index in an array
I have an array of objects similar to:
[
{
start : 0.000,
end : 0.100
},
{
start : 0.100,
end : 0.200
},
{
start : 0.200,
end : 0.300
}
]
Is there a quick way for me to query this object frame after frame to find out where a value (in this case the current time of a audio playback) lies?
After chatting with my coworkers, they have suggested I enumerate this into a large array of indexed values with references to which index they are associated with, for instance
[000] = 0
[001] = 0
...
[100] = 1
...
[200] = 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
索引策略将是最快的,但是您不需要这样做吗?:
或者,您可以在第一个示例中循环并选择相关对象,假设您的数组中不超过 1000 个对象应该足够快:
这应该返回具有指定开始时间的对象的索引:
The indexing strategy would be the fastest, however don't you need to do it more like this?:
Alternatively you can loop through and select the relevant object in your first example, assuming that there's no more than say 1000 objects in your Array it should be more than fast enough:
This should return the index of an object with the specified start time:
也许更好的解决方案是使用
Dictionary
(链接)。字典是存储关联数据的快速且简单的方法。
虽然我不完全确定您要解决什么问题,所以其他数据类型可能更适合您。我只是让您知道您可以使用的另一个选择。
Maybe a better solution would be to use a
Dictionary
(link).Dictionaries are fast and easy ways to store associative data.
Though I'm not entirely sure what problem you're trying to solve, so other data types may be more appropriate for you. I'm just letting you know of another option you have available to you.