# Beginner scope problem I guess? Please help!

**URL:** <https://forum.kirupa.com/t/beginner-scope-problem-i-guess-please-help/308682>\
**Category:** flash\
**Created:** [April 28, 2010, 6:43am UTC](https://forum.kirupa.com/t/beginner-scope-problem-i-guess-please-help/308682 "2010-04-28T06:43:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![user\_name1](https://avatars.discourse-cdn.com/v4/letter/u/e8c25b/32.png) [@user\_name1](https://forum.kirupa.com/u/user_name1)\
**Post date:** [April 28, 2010, 6:43am UTC](https://forum.kirupa.com/t/beginner-scope-problem-i-guess-please-help/308682/1 "2010-04-28T06:43:47Z")

</div>

Hi. I am having trouble just getting started on a simple as3 image slider. I cannot figure out oop in flash.

In my fla file I have:

```auto

var datastr:String = '["img1.jpg", "img2.jpg", "img3.jpg", "img4.jpg", "img5.jpg", "img6.jpg", "img7.jpg", "img8.jpg"] ';
var slideshow:Slideshow = new Slideshow(datastr);
addChild(slideshow);

```

then Slideshow is:

```auto

package {
    
    import com.adobe.serialization.json.JSON
    import flash.display.*
    import flash.events.*
    import flash.utils.*
    
    public class Slideshow extends Sprite
    {
        
        // Constants:
        // Public Properties:
        // Private Properties:
        
        private var container:Sprite;
        
        private var displayTimer:Timer;
        private var displayTimerDelay:Number = 4000;
        
        private var queue:Array;
        
        private var currentIndex:int = -1;
        
    
        // Initialization:
        public function Slideshow(jsonString:String) 
        {
                var container = new Sprite();
                addChild(container);
                
                //parse the data
                parseJsonString(jsonString);
                
                //initialize
                init();
        }
    
        // Public Methods:
        // Protected Methods:
        private function parseJsonString(str):void
        {
            queue = new Array();
            
            var o:Object = JSON.decode(str);
            
            var item:Object = new Object();
            
            for (var i:int = 0; i < o.length; i++) 
            {
                item.url = o*;
                queue.push(item);
            }
        }
        
        private function init():void
        {
            //start the timer
            displayTimer = new Timer(displayTimerDelay);
            displayTimer.addEventListener(TimerEvent.TIMER, display);
            displayTimer.start();
        }
        
        private function display(e:TimerEvent):void
        {
            //stop the timer while we animate
            displayTimer.reset();
            
            var i:int = getNextIndex();
            
            var temp = currentIndex;
            
            //update current index
            currentIndex = i;
            
            var currentTime:Date = new Date();
            trace("Time: " + currentTime.time);
            trace("queue.length is: "+queue.length+" and currentIndex was: " + temp + " and now is: " + currentIndex + " and i is: " +i);
            
            //restart the timer
            //displayTimer.start();
        }
        
        private function getNextIndex():int
        {
            var i:int = currentIndex + 1;
            
            //trace("i is:" + i + " and queue.length is: " +queue.length + " and currentIndex is: " + currentIndex);
            if(i == queue.length)
            {
                i = 0;
            } 
            return i;
        }
    }
    
}

```

I feel like I should only get the trace to output one time because I stop the timer and never start it again. I don’t really understand why, but I am guessing that I don’t just get one instance of the Slideshow. New instances keep getting assigned or something because this is the trace output:

```auto
Time: 1272436012629
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436012797
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436012965
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436013133
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436013301
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436013461
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436013629
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436013797
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436013965
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Time: 1272436014133
queue.length is: 8 and currentIndex was: -1 and now is: 0 and i is: 0
Debug session terminated.

```

Also, why is my currentIndex not getting updated? I tried every combination of incrementing I could think of, but the output is the same. I guess all of my questions have the same answer, but another one is why isn’t my timer taking four seconds to go off?
