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

image slider

New Here ,
Apr 16, 2014 Apr 16, 2014

Copy link to clipboard

Copied

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

TOPICS
ActionScript

Views

219

Translate

Translate

Report

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

correct answers 1 Correct answer

LEGEND , Apr 16, 2014 Apr 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.

Votes

Translate

Translate
LEGEND ,
Apr 16, 2014 Apr 16, 2014

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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