Copy link to clipboard
Copied
Hi there. I can't seem to get the next/previous buttons working. I get the error "
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
nextImg is a function. use:
nextImg() to call it, not nextImg.play()
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Scene 1, Layer 'As', Frame 1, Line 91 | 1061: Call to a possibly undefined method play through a reference with static type Function. |
which is about this line of code:
nextImg.play(); |
Copy link to clipboard
Copied
nextImg is a function. use:
nextImg() to call it, not nextImg.play()
Copy link to clipboard
Copied
says this now about
Scene 1, Layer 'As', Frame 1, Line 103 | 1180: 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() ;
}
Copy link to clipboard
Copied
nevermind, should be prevImg();
thanks for your help
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
use:
imgCntrTxt.text = (imgCntr+1).toString() + "/" + imgCntrTotal.toString() ;
Copy link to clipboard
Copied
I already did that, didn't I? (at the end, with 'void').
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
there are two locations, at least, where you need to change your code.
(continue on your duplicate thread.)