Skip to main content
Known Participant
April 17, 2014
Answered

next/previous image in imageslider

  • April 17, 2014
  • 1 reply
  • 1128 views

Hi there. I can't seem to get the next/previous buttons working. I get the error "

1061: Call to a possibly undefined method addEventListener through a reference with static type function

What's going wrong?

This is the code:

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

var imgVisible:Boolean = true;

//Init

playBtn.stop();

stopBtn.stop();

nextBtn.stop();

prevBtn.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);

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

}

//Previous

function prevBtnOver(e:MouseEvent){

          prevBtn.gotoAndStop(2);

}

function prevBtnOut(e:MouseEvent){

          prevBtn.gotoAndStop(1);

}

function prevBtnDown(e:MouseEvent){

          prevBtn.play();

}

//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 prevImg(){

          if(imgCntr == 0)

          {

                    imgCntr = imgArray.length -1;

          }

                    imgCntr--;

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

                    imgLoader.load(imgRequest);

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

          }

function tfF():void{

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

}

Help much appreciated

This topic has been closed for replies.
Correct answer kglad

nextImg is a function.  use:

nextImg() to call it, not nextImg.play()

1 reply

kglad
Community Expert
Community Expert
April 17, 2014

click file>publish settings>swf and tick 'permit debugging'.  retest.

the problematic line number will be in the error message allowing you to pinpoint and correct the error.

if you need more help, copy and paste the complete error message and highlight (bold) the problematic line of code.

Known Participant
April 17, 2014
Scene 1, Layer 'As', Frame 1, Line 911061: Call to a possibly undefined method play through a reference with static type Function.

which is about this line of code:


nextImg.play();
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 17, 2014

nextImg is a function.  use:

nextImg() to call it, not nextImg.play()