Pictures Loading Due SetInterval

Heres the Problem …

I have build in Interval with Set Interval, works good so far. Now i wanted to delete the Interval in the moment, the Picture is loaded from the Folder. If there is no picture in the Folder yet (which can happened, coz they are generated dynamicaly), i wanted to restart the Interval …

below is my code so far.


sessionid = "23e14457511e6ab89d040546ff86fff9";
var intervalId:Number;
var count:Number = 0;
var maxCount:Number = 99;
var duration:Number = 5000;

function executeCallback():Void {
 this.uploadfoto.loadMovie("thumbs/" + sessionid + ".jpg");
 if(count >= maxCount) {
 clearInterval(intervalId);
 }
 count++;
}

function beginInterval():Void {
 if(intervalId != null) {
 trace("clearInterval");
 clearInterval(intervalId);
 }
 intervalId = setInterval(this, "executeCallback", duration);
}
uploaden.onRelease = function(){
	beginInterval();
    beginInterval();
    beginInterval();
}

any hints how i can achieve this??

cheers