Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

image slider counter

New Here ,
Apr 17, 2014 Apr 17, 2014

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() ;

          }

TOPICS
ActionScript
350
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2014 Apr 17, 2014

again,

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

should be

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

in ALL locations (prevImg included)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2014 Apr 17, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2014 Apr 17, 2014

ANY idea? It goes from 1/8 up to 9/8, where it starts to look for an undefined image.

Would there be something wrong with the nextImg function?

function nextImg(){

          if(imgCntr < imgCntrTotal){

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

          }else{

                    imgCntr = 0;

          }

oh, by the way it's also stuck on the current picture. I can click the previous button but it doesn't go there...

It's just this one problem, then I'm finished.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2014 Apr 17, 2014
LATEST

use:

function nextImg(){

          if(imgCntr < imgCntrTotal-1){

                    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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines