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

next/previous image in imageslider

New Here ,
Apr 17, 2014 Apr 17, 2014

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

TOPICS
ActionScript
982
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

correct answers 1 Correct answer

Community Expert , Apr 17, 2014 Apr 17, 2014

nextImg is a function.  use:

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

Translate
Community Expert ,
Apr 17, 2014 Apr 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.

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

nextImg is a function.  use:

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

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

says this now about

Scene 1, Layer 'As', Frame 1, Line 1031180: Call to a possibly undefined method prevBtn.

related code:

var prevBtn:MovieClip =  menuMc.prevBtnMc;

//Previous

prevBtn.addEventListener(MouseEvent.MOUSE_DOWN,prevBtnDown);

prevBtn.addEventListener(MouseEvent.MOUSE_OVER,prevBtnOver);

prevBtn.addEventListener(MouseEvent.MOUSE_OUT,prevBtnOut);

//Previous

function prevBtnOver(e:MouseEvent){

          prevBtn.gotoAndStop(2);

}

function prevBtnOut(e:MouseEvent){

          prevBtn.gotoAndStop(1);

}

function prevBtnDown(e:MouseEvent){

          prevBtn();

}

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

          }

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

nevermind, should be prevImg();

thanks for your help

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

you're welcome.

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

oh, btw. My counter also starts at 0/8, how do I make it look from 1/8 to 8/8 back to 1/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
Community Expert ,
Apr 17, 2014 Apr 17, 2014

use:

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
New Here ,
Apr 17, 2014 Apr 17, 2014

I already did that, didn't I? (at the end, with 'void').

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

It now goes up to 9/8...

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

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

}

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

there are two locations, at least, where you need to change your code.

(continue on your duplicate thread.)

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