Tuesday, December 10, 2024

Create a Flash Slideshow with MovieClips Using the Fader API

This tutorial will show you how to create a slideshow using the Fader API. The Fader API can be used to create a sequence of fade animations and slideshows using less code.


Note: In this tutorial we are going to use the Fader API to create a slideshow from DisplayObjects (the base class for all objects that can be placed on the display list) that are present in the stage. This tutorial is written with the basic to intermediate developer in mind.


Difficulty: Basic to Intermediate. Even entry-level programmers and beginners can use this API easily. Some of the features incude:


  • Less code
  • Slide to slide transition
  • No Preloader needed
  • Customized events to handle slideshow

Flash Version: Flash 9 + Actionscript 3.0

Using Fader Class

We are going to use the Fader Class to create our Slideshow/animate DisplayObjects present on the stage. If you are trying to load images from an external URL use FaderFileMaterial instead.


Import the Classes:

import com.utils.Fader.*;
import com.utils.Fader.FaderItems;
import com.utils.Fader.Events.*;

Importing the external classes makes them available for use in our code.


Defining the duration variables:

var fadeInDuration:Number = 1; var fadeOutDuration:Number = 3; 

Duration variables defines the time in seconds that the transition should take.


Create FaderItems:

var _faderItems:FaderItems = new FaderItems( 
fadeInDuration, fadeOutDuration );
_faderItems.addObject(rect1);
_faderItems.addObject(rect2);
_faderItems.addObject(rect3);

FaderItems is used as a stack to store Display Object and TextField, The added items will be taken into account for creating the animation.


Just pass the instance name provided in the property window to add it into the animation.


Finally to create the Fader:

var _fader:Fader = new Fader(_faderItems,5000,true);
_fader.addEventListener(ObjectEvent.FADER_INIT, handleInit);
_fader.addEventListener(ObjectEvent.FADER_ITEM_INIT, 
handleItemInit);
_fader.addEventListener(ObjectEvent.FADER_ITEM_COMPLETE, 
handleItemComplete);
_fader.addEventListener(ObjectEvent.FADER_COMPLETE, 
handleComplete);
_fader.start();

Here we are just passing the FaderItems Object that we created in the step above. The second argument is the delay duration. The third argument is Boolean and specifies whether the animation should repeat after EOF and fades DisplayObjects using the given delay. Using the Fader Class, it is easy to create Slideshow or Fade animations.

Online Documents for Classes used



Entire Example

import com.utils.Fader.*;
import com.utils.Fader.FaderItems;
import com.utils.Fader.Events.*;

var fadeInDuration:Number = 1;
var fadeOutDuration:Number = 3;

var _faderItems:FaderItems = new FaderItems( fadeInDuration, fadeOutDuration );
_faderItems.addObject(rect1);
_faderItems.addObject(rect2);

var _fader:Fader = new Fader(_faderItems,5000, true);
_fader.addEventListener(ObjectEvent.FADER_INIT, handleInit);
_fader.addEventListener(ObjectEvent.FADER_ITEM_INIT, handleItemInit);
_fader.addEventListener(ObjectEvent.FADER_ITEM_COMPLETE, handleItemComplete);
_fader.addEventListener(ObjectEvent.FADER_COMPLETE, handleComplete);
_fader.start();

function handleInit(e:ObjectEvent):void { trace("::::::::::Fader Started:::::::::") }
function handleItemInit(e:ObjectEvent):void { trace("init:: "+e.targetObject.name) }
function handleItemComplete(e:ObjectEvent):void { trace("complete:: "+e.targetObject.name) }
function handleComplete(e:ObjectEvent):void { trace(":::::::::Fader Complete:::::::::") }

stop_mc.addEventListener(MouseEvent.CLICK, handleStop) function handleStop(e:MouseEvent):void{ _fader.stop(); }

play_mc.addEventListener(MouseEvent.CLICK, handlePlay) function handlePlay(e:MouseEvent):void{ _fader.start(); }

For a more detailed description see the Documentation:


Download the example source to try the code out for yourself!

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Popular Articles

Featured