Multiple onMetaData?

I have a correctly working FLV video play. But now I need to make it load “infinite” videos in “infinite movieclips” at the same time. And that’s where it get tricky.

Obviously I can’t duplicate or copy-paste infinite metaDataHandler() functions.

I thought of creating nested Arrays to take the place of the metaDataHandler function. So I nested a number of array variables (object[][], metaDataHandlerArray[][] and VIDEOduration[][]) to prepare it.

In short i have now the following. “j” represents ‘movieclip’ and “k” represents one of multiple videos in each movieclip. It performs a for() loop for “k”, within a for() loop for “j” and within that is the video and meta data part.


...
object[j][k].onMetaData = metaDataHandlerArray[j][k];
...

and in the array-function I have


...
metaDataHandlerArray[j][k] = function (data:Object){
     VIDEOduration[j][k] = data.duration;
     trace(VIDEOduration[j][k] +" j="+j+" k="+k)
}
...

Now it almost traces/works correct… almost. I test with one MC with 2 videos, it traces

10.3 j=1 k=2
9.933 j=1 k=2

So what seems to be happening is weird. It does read two different durations for the videos but reads the same value for ‘k’. It should trace 1 and 2 but it traces 2 and 2.
If I place a trace(k) before metaDataHandlerArray[j][k] and indeed it traces 1 and 2 before the traced lines above so I’m 99% positive the loops finish/complete before the meta data is read/set

Anybody any clue how to solve this?
P