MaizeNBlueJ Posted August 3, 2011 Share Posted August 3, 2011 Alright guys, I'm trying to apply a very basic Photo Album Slideshow to a web site. I used Adobe's default template, which works flawlessly, until you try and set the Autostart variable to true. At that point, it balks at you, and the controls don't work. Here is the error message: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Burger_fla::MainTimeline/fl_startSlideShow()[burger_fla.MainTimeline::frame1:47] at Burger_fla::MainTimeline/frame1()[burger_fla.MainTimeline::frame1:70] Line 47 contains this code: slideshowTimer.start(); Line 70 contains this code: fl_startSlideShow(); Here's the entire code contents: // USER CONFIG SETTINGS ===== var autoStart:Boolean = true; //true, false var secondsDelay:Number = 30; // 1-60 // END USER CONFIG SETTINGS // EVENTS ===== playPauseToggle_mc.addEventListener(MouseEvent.CLICK, fl_togglePlayPause); function fl_togglePlayPause(evt:MouseEvent):void { if(playPauseToggle_mc.currentLabel == "play") { fl_startSlideShow(); playPauseToggle_mc.gotoAndStop("pause"); } else if(playPauseToggle_mc.currentLabel == "pause") { fl_pauseSlideShow(); playPauseToggle_mc.gotoAndStop("play"); } } next_btn.addEventListener(MouseEvent.CLICK, fl_nextButtonClick); prev_btn.addEventListener(MouseEvent.CLICK, fl_prevButtonClick); function fl_nextButtonClick(evt:MouseEvent):void { fl_nextSlide(); } function fl_prevButtonClick(evt:MouseEvent):void { fl_prevSlide(); } var currentImageID:Number; var slideshowTimer:Timer; var appInit:Boolean; function fl_slideShowNext(evt:TimerEvent):void { fl_nextSlide(); } // END EVENTS // FUNCTIONS AND LOGIC ===== function fl_pauseSlideShow():void { slideshowTimer.stop(); } function fl_startSlideShow():void { slideshowTimer.start(); } function fl_nextSlide():void { currentImageID++; if(currentImageID >= totalFrames) { currentImageID = 0; } gotoAndStop(currentImageID+1); } function fl_prevSlide():void { currentImageID--; if(currentImageID < 0) { currentImageID = totalFrames+1; } gotoAndStop(currentImageID-1); } if(autoStart == true) { fl_startSlideShow(); playPauseToggle_mc.gotoAndStop("pause"); } else { gotoAndStop(1); } function initApp(){ currentImageID = 0; slideshowTimer = new Timer((secondsDelay*1000), 0); slideshowTimer.addEventListener(TimerEvent.TIMER, fl_slideShowNext); } if(appInit != true){ initApp(); appInit = true; } // END FUNCTIONS AND LOGIC I'm a flash nebie, so please be gentle. Thanks for any help you can provide! Quote Link to comment https://forums.phpfreaks.com/topic/243716-flash-professional-cs5-simple-photo-album-template/ Share on other sites More sharing options...
IQAndreas Posted August 17, 2011 Share Posted August 17, 2011 The problem is, you are trying to start the timer before you have created it (you create it in the "appInit" function). By moving around the functions like this, you make sure your app will always initialize before the timer is forced to start: // USER CONFIG SETTINGS ===== var autoStart:Boolean = true; //true, false var secondsDelay:Number = 30; // 1-60 // END USER CONFIG SETTINGS // INIT ===== var currentImageID:Number; var slideshowTimer:Timer; var appInit:Boolean; function initApp(){ currentImageID = 0; slideshowTimer = new Timer((secondsDelay*1000), 0); slideshowTimer.addEventListener(TimerEvent.TIMER, fl_slideShowNext); } if(appInit != true){ initApp(); appInit = true; } // EVENTS ===== playPauseToggle_mc.addEventListener(MouseEvent.CLICK, fl_togglePlayPause); function fl_togglePlayPause(evt:MouseEvent):void { if(playPauseToggle_mc.currentLabel == "play") { fl_startSlideShow(); playPauseToggle_mc.gotoAndStop("pause"); } else if(playPauseToggle_mc.currentLabel == "pause") { fl_pauseSlideShow(); playPauseToggle_mc.gotoAndStop("play"); } } next_btn.addEventListener(MouseEvent.CLICK, fl_nextButtonClick); prev_btn.addEventListener(MouseEvent.CLICK, fl_prevButtonClick); function fl_nextButtonClick(evt:MouseEvent):void { fl_nextSlide(); } function fl_prevButtonClick(evt:MouseEvent):void { fl_prevSlide(); } function fl_slideShowNext(evt:TimerEvent):void { fl_nextSlide(); } // END EVENTS // FUNCTIONS AND LOGIC ===== function fl_pauseSlideShow():void { slideshowTimer.stop(); } function fl_startSlideShow():void { slideshowTimer.start(); } function fl_nextSlide():void { currentImageID++; if(currentImageID >= totalFrames) { currentImageID = 0; } gotoAndStop(currentImageID+1); } function fl_prevSlide():void { currentImageID--; if(currentImageID < 0) { currentImageID = totalFrames+1; } gotoAndStop(currentImageID-1); } if(autoStart == true) { fl_startSlideShow(); playPauseToggle_mc.gotoAndStop("pause"); } else { gotoAndStop(1); } // END FUNCTIONS AND LOGIC As I am unable to test the code, let me know if you have any other problems with it. Quote Link to comment https://forums.phpfreaks.com/topic/243716-flash-professional-cs5-simple-photo-album-template/#findComment-1258458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.