Skip to main content
Known Participant
April 16, 2014
Answered

image slider

  • April 16, 2014
  • 1 reply
  • 276 views
i






















































This is the code of my img slider, but the counter starts at 0/8 and the next/prev doesn't work. What am I missing?

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 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 (5000,0);

var imgVisible:Boolean = true;

//Init

nextBtn.stop();

prevBtn.stop();

playBtn.stop();

stopBtn.stop();

imgLoader.load(imgRequest);

imgCntrTxt.text = (imgCntr).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);

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

}

//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.toString() + "/" + imgCntrTotal.toString();

}

function tfF():void{

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

}

Help is appreciated,

gr, Matthijs

This topic has been closed for replies.
Correct answer Ned Murphy

As far as starting at 0, that is likely becaiusew you set it to start at zero and don't increment the counter until after you are loading the second image.   Try incrementing it when you load the first image.  You might need to not set it back to 0 either when you reach the end if the intention is to loop...  when you reach the end you should go back to 1, not 0.

You don't appear to have any event listeners for the previous and next buttons, so that might be the reason they don't work.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
April 16, 2014

As far as starting at 0, that is likely becaiusew you set it to start at zero and don't increment the counter until after you are loading the second image.   Try incrementing it when you load the first image.  You might need to not set it back to 0 either when you reach the end if the intention is to loop...  when you reach the end you should go back to 1, not 0.

You don't appear to have any event listeners for the previous and next buttons, so that might be the reason they don't work.