A for loop issue

I am reading in a text document and if my text document is “undefined” I need a “no documents selected” message to appear. If the document contains items then a “selected document” message appears. The text file is document.txt and has the form

&doc0=test&pdf0=test.pdf&doc1=test2&pdf1=test2.pdf

The issue is my “no document selected” message is appearing even though there are items in the document. The reason is it’s running through the for loop, it sees two items and 8 items as undefined. How can I get around this? Here is my code:


trace("id = "+id);
/////// LOAD ID SESSION VARIABLE FROM ASP INTO 
/////// TEXT BOX 
myDataText.text = id;
//_root.stop();
//LOAD ID txt FILE 
MyLoadCID = new LoadVars();
MyLoadCID.load(+id+"CdTypes/ID.txt");
MyLoadCID.onLoad = function(success) {
    if (success) {
        trace("loaded");
        myVar = MyLoadCID.ID;        
        info(myVar);        
    } else {
        trace("not loaded");
    }
};

//START FUNCTION INFO 
function info(myVar) {    
    MyLoadVars = new LoadVars();
    MyLoadVars.load(+id+"CDTypes/"+myVar+"DOCUMENT.txt","document");    
    MyLoadVars.onLoad = function(success) {
        if (success) {
            trace("here");
            for (i=0; i<10; i++){                    
                //check for undefined
                if (this["doc"+i] == undefined) {                    
                    _root["press_mc"+i]._x = 800;
                    // add no document select text                    
                    _root.attachMovie("noDocumentsSelected","noDo",50);
                    _root["noDo"]._x = 300;
                    _root["noDo"]._y = 50;
                } else {                
                    
                    // 9.10.09 add general documents 
                    //make sure all general documents are listed first in text document
                    _root.attachMovie("generalHeader","gen1",50);
                    _root["gen1"]._x = 300;
                    _root["gen1"]._y = 50;

                    //this creates the text field
                    _root.attachMovie("PressText","press_mc"+i,60+i);
                    _root["press_mc"+i].name.text = this["doc"+i];
                    _root["press_mc"+i]._x = 330;
                    _root["press_mc"+i]._y = 80+(i*20);

                    //sets the text width to character length
                    _root["press_mc"+i].name.autoSize = true;

                    //this creates the button it overlays the text at a higher level
                    _root.attachMovie("PressText1","press_mc1"+i,70+i);
                    _root["press_mc1"+i].name1.text = this["pdf"+i];
                    _root["press_mc1"+i]._x = 330;
                    _root["press_mc1"+i]._y = 80+(i*20);
                    _root["press_mc1"+i]._alpha = 0;

                    // set both text boxes to same width
                    _root["press_mc1"+i].name1._width = _root["press_mc"+i].name._width;

                    //set global var poodoo to be used in spacing industry documents
                    _global.poodoo = _root["press_mc1"+i]._y=80+(i*20);

                    //add the document icon
                    _root.attachMovie("press_icon","icon"+i,85+i);
                    _root["icon"+i]._x = 300;
                    _root["icon"+i]._y = 76+(i*20);

                    //correct FF getURL issue
                    output_txt.text = this._url;
                    var swfUrl:String = _root._url;
                    var lastSlashIndex:Number = swfUrl.lastIndexOf("/");
                    var pipeIndex:Number = swfUrl.indexOf("|");
                    var baseUrl:String;
                    if (pipeIndex>=0) {
                        baseUrl = swfUrl.substring(0, pipeIndex);
                        baseUrl += ":";
                    } else {
                        baseUrl = "";
                    }
                    baseUrl += swfUrl.substring(pipeIndex+1, lastSlashIndex+1);
                    //
                    _root["press_mc1"+i].onRelease = function() {
                        //
                        var targetUrl:String = baseUrl+"documents/"+this.name1.text;
                        getURL(targetUrl, "_blank");
                        //trace("documents/"+this.name1.text);
                    };

                }
            }
        } else {
            trace("not loaded");
            
        }
    };
}