var start_offset = -1; mySyncFlashHx = new syncFlashHx(); var checkOffset = function (startOffset, callCount) { if (callCount == 0) { return; } var timeTest = mySyncFlashHx.getTimeCode(); if (timeTest < startOffset) { mySyncFlashHx.setTimeCode(startOffset); setTimeout(function () { checkOffset(startOffset, (callCount - 1)); }, 2000); } }; $(document).ready(function() { if (start_offset != "" && start_offset != null && start_offset != 'undefined') { try { //this needs to be called in a loop where we check the current timecode to make sure it worked mySyncFlashHx.setTimeCode(start_offset); setTimeout(function () { checkOffset (start_offset, 8); }, 2000); } catch (err) {} } });