Jump to content

Flash Professional CS5 Simple Photo Album Template


MaizeNBlueJ

Recommended Posts

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!

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.