The loopindex has no effect and would probably break the loop. Take that out first. Then if nothing is spawning you can debug with Browser object and 'log', you can see what value in the array it finds. You don't have any handling for if it can't find the parameter string. We also don't see how you call the function. Do some logging and work it out. If it's spawning at 0 it might not be able to find anything, you have a lot of conditions that if just one isn't true then nothing will happen, it's down to you to put some logging in and try and find the exact place it goes wrong then you can work out why.