Skip to main content
Known Participant
April 17, 2014
Question

image slider counter

  • April 17, 2014
  • 1 reply
  • 373 views

My image counter goes up to 9/8... It has only 8 pictures.

I got it starting at 1/8 up to 9/8 back to 1/8. What's wrong?

Thanks for help

import fl.containers.UILoader;

//Declaring Variables

var menu:MovieClip = menuMc;

// var prevBtn:MovieClip = menuMc.prevBtnMc;

// var nextBtn:MovieClip = menuMc.nextBtnMc;

var playBtn:MovieClip =  menuMc.playBtnMc;

var stopBtn:MovieClip =  menuMc.stopBtnMc;

var nextBtn:MovieClip =  menuMc.nextBtnMc;

var prevBtn:MovieClip =  menuMc.prevBtnMc;

var imgFolder:String = "imgs/"

var imgArray:Array = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg");

var imgLoader:UILoader = imgLoader;

var imgCntr:uint = 0;

var imgCntrTotal:uint = imgArray.length;

var imgRequest:URLRequest = new URLRequest(imgFolder + imgArray[imgCntr]);

var imgCntrTxt:TextField = menu.imgCntrTxtTf;

var slideShowTimer:Timer = new Timer (4000,0);

var imgVisible:Boolean = true;

//Init

playBtn.stop();

stopBtn.stop();

nextBtn.stop();

prevBtn.stop();

imgLoader.load(imgRequest);

imgCntrTxt.text = (imgCntr+1).toString() + "/" + imgArray.length.toString();

//Events

//Play

playBtn.addEventListener(MouseEvent.MOUSE_DOWN,playBtnDown);

playBtn.addEventListener(MouseEvent.MOUSE_OVER,playBtnOver);

playBtn.addEventListener(MouseEvent.MOUSE_OUT,playBtnOut);

//Stop

stopBtn.addEventListener(MouseEvent.MOUSE_DOWN,stopBtnDown);

stopBtn.addEventListener(MouseEvent.MOUSE_OVER,stopBtnOver);

stopBtn.addEventListener(MouseEvent.MOUSE_OUT,stopBtnOut);

//Next

nextBtn.addEventListener(MouseEvent.MOUSE_DOWN,nextBtnDown);

nextBtn.addEventListener(MouseEvent.MOUSE_OVER,nextBtnOver);

nextBtn.addEventListener(MouseEvent.MOUSE_OUT,nextBtnOut);

//Previous

prevBtn.addEventListener(MouseEvent.MOUSE_DOWN,prevBtnDown);

prevBtn.addEventListener(MouseEvent.MOUSE_OVER,prevBtnOver);

prevBtn.addEventListener(MouseEvent.MOUSE_OUT,prevBtnOut);

//Timer

slideShowTimer.addEventListener(TimerEvent.TIMER,timePassed);

//EventHandlers

//Play

function playBtnOver(e:MouseEvent){

          playBtn.gotoAndStop(2);

}

function playBtnOut(e:MouseEvent){

          playBtn.gotoAndStop(1);

}

function playBtnDown(e:MouseEvent){

          //Slideshow / Timer starten

          slideShowTimer.start();

}

//Stop

function stopBtnOver(e:MouseEvent){

          stopBtn.gotoAndStop(2);

}

function stopBtnOut(e:MouseEvent){

          stopBtn.gotoAndStop(1);

}

function stopBtnDown(e:MouseEvent){

          // Slideshow / Timer Stoppen

          slideShowTimer.stop();

}

//Next

function nextBtnOver(e:MouseEvent){

          nextBtn.gotoAndStop(2);

}

function nextBtnOut(e:MouseEvent){

          nextBtn.gotoAndStop(1);

}

function nextBtnDown(e:MouseEvent){

          nextImg();

}

//Previous

function prevBtnOver(e:MouseEvent){

          prevBtn.gotoAndStop(2);

}

function prevBtnOut(e:MouseEvent){

          prevBtn.gotoAndStop(1);

}

function prevBtnDown(e:MouseEvent){

          prevImg();

}

//SlideShowTimer

function timePassed(e:TimerEvent){

          imgLoader.addEventListener(Event.ENTER_FRAME,fadeImg);

}

//Functions

function fadeImg(e:Event){

          if(imgVisible == true){

                    imgLoader.alpha = imgLoader.alpha - 0.05;

                    if(imgLoader.alpha <= 0){

                              imgVisible = false;

                              nextImg();

 

                    }

          }

 

          if(imgVisible == false){

                    imgLoader.alpha = imgLoader.alpha + 0.05;

                    if(imgLoader.alpha >= 1){

                              imgVisible = true;

                              imgLoader.removeEventListener(Event.ENTER_FRAME,fadeImg);

                    }

          }

 

 

}

function nextImg(){

          if(imgCntr < imgCntrTotal){

                    imgCntr++; //staat gelijk aan imgCntr + 1

          }else{

                    imgCntr = 0;

          }

                    imgRequest = new URLRequest(imgFolder + imgArray[imgCntr]);

                    imgLoader.load(imgRequest);

                    imgCntrTxt.text = (imgCntr+1).toString() + "/" + imgCntrTotal.toString();

}

function prevImg(){

          if(imgCntr == 0)

          {

                    imgCntr = imgArray.length - 1;

          }

                    imgCntr--;

                    imgRequest = new URLRequest (imgFolder + imgArray [imgCntr]);

                    imgLoader.load(imgRequest);

                    imgCntrTxt.text = imgCntr.toString() + "/" + imgCntrTotal.toString() ;

          }

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 17, 2014

again,

imgCntrTxt.text = imgCntr.toString() + "/" + imgCntrTotal.toString() ;

should be

imgCntrTxt.text = (imgCntr+1).toString() + "/" + imgCntrTotal.toString() ;

in ALL locations (prevImg included)

Known Participant
April 17, 2014

okay, but it still goes up to 9/8...