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
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: