# For loop indexing problem?

**URL:** <https://forum.kirupa.com/t/for-loop-indexing-problem/240620>\
**Category:** Uncategorized\
**Created:** [October 4, 2007, 2:57pm UTC](https://forum.kirupa.com/t/for-loop-indexing-problem/240620 "2007-10-04T14:57:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinswartsel](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/justinswartsel/32/4051_2.png) [@justinswartsel](https://forum.kirupa.com/u/justinswartsel)\
**Post date:** [October 4, 2007, 2:57pm UTC](https://forum.kirupa.com/t/for-loop-indexing-problem/240620/1 "2007-10-04T14:57:18Z")

</div>

Hey everyone, this problem could easily somehow lie somewhere, but I’m wondering if anyone can look at this and see something i’m not. I apologize for the limited context. I basically have a counter that counts how many times this function has run… inside of the for loop, it traces that counter plus the index. The index is incrementing (i++) but at one point it decrements and I get an error. Any possible causes??

```auto
var sscount:int = 0;
function loadPicsXML(l:XML):Slideshow {

    
    count = 0;
    var tempPicArray:Array = new Array();
    var tempPic:Picture;
    
    numPics = l.child("*").length();

    var tempArr:Array = new Array();
    var tIndex:int;
    var tl:Loader;
    var tba:ByteArray;
    sscount++;
    for (var i:int = 0; i < numPics; i++) {
        tIndex = picIndex(l.photo*.@id);
        
        if (tIndex < 0) {
            
            tempArr*= new CLoader(i);
            tempArr*.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function (e:IOErrorEvent) { 
                                                                                                          trace("Image not found: " + e.target.loaderURL); 
                                                                                                         } );
            tempArr*.load(new URLRequest("Images/"+l.photo*.@src));
            tempPic = new Picture(tempArr*, l.photo*.@picCaption, l.photo*.@id);
            tempArr*.contentLoaderInfo.addEventListener(Event.COMPLETE, checkLoad);
          
            PICS.push(tempPic);
            tempPicArray.push(tempPic);
            
        } else {
            checkLoad(null);
            
            
            if(PICS[tIndex].pic.content == null){
                var ld:CLoader = PICS[tIndex].getPic();
                tempPicArray.push(new Picture(ld,PICS[tIndex].picCaption, PICS[tIndex].id));
            }else{
                trace("else else " + PICS[tIndex].id);
                var tb:Bitmap = new Bitmap();
                tb.bitmapData = PICS[tIndex].pic.content.bitmapData.clone();
                tempPicArray.push(new Picture(tb,PICS[tIndex].picCaption, PICS[tIndex].id));
                
            }
            
        }
        
        trace(":: " + sscount + " " + i);
    }

    return new Slideshow(Slideshow.ARRAYTYPE,tempPicArray,l.@x.valueOf(),l.@y.valueOf(),l.@width.valueOf(),l.@height.valueOf(),l.@speed.valueOf(),l.@showBorder == "false"?false:true,l.@showDropshadow == "true"?true:false,l.@showCaption == "true"?true:false);

}

```

and I get this trace…

```auto
:: 1 0
:: 1 1
:: 1 2
:: 2 0
:: 3 0
:: 3 1
:: 3 2
:: 4 0
:: 4 1
:: 5 0
:: 6 0
:: 6 1
:: 6 2
:: 6 3
:: 6 4
:: 6 5
:: 6 6
:: 7 0
:: 7 1
:: 7 2
:: 7 3
:: 7 2
TypeError: Error #1010: A term is undefined and has no properties.
    at harris9_fla::MainTimeline/loadPicsXML()
    at harris9_fla::MainTimeline/doHotelsXML()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/flash.net:URLLoader::onComplete()

```

Note the last line of the trace before the error. The index goes from 3 to 2. I know the root of my error is probably elsewhere, but i’m wondering if anyone can offer any help on why I’d get that index value?

Thanks!!

justin
