Home » ActionScript 3.0

Fader API:Slideshow with MovieClips on stage

12 February 2009 No Comment
Share on Facebook

The aim of this tutorial is to create slideshow using the FaderAPI.
Fader API can be used to create Sequence of fade animations, Slideshows with less code.

Note:
In this tutorial we are going to use Fader API to create slideshow from DisplayObjects present in stage. Not the dynamic one as we created in previous version.
This tutorial is indented for basic – intermediate skill set. Follow the link to create slideshow dynamically using FaderFileMaterial

Difficulty:
Basic – Intermediate.
Even the entry level programmers and beginners can use this API easily.

Features:
Some features are
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 Fader Class to create Slideshow/animate DisplayObjects present at stage. If you are looking to load image from external URL use FaderFileMaterial.

Import the Classes:

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

Importing the external classes makes the external classes available to use in Code.

Defining the duration variables:

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

Duration variables define the time in seconds with the transition should take place.

Create FaderItems:

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

FaderItems used as 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 into animation.

Finally to create 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 above step.

Second argument is the delay duration.

Third argument is Boolean which specifies whether the animation should repeat after EOF.

Fades DisplayObjects on given delay. Using the Fader Class it is easy to create Slideshow or of Fade animation

Online Documents for Classes used

Fader: http://www.designscripting.com/wp-content/uploads/2009/01/fader.html
Faderitems: http://www.designscripting.com/wp-content/uploads/2009/01/faderitems.html

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 more detailed description use the Documentation.

Fader Class http://www.designscripting.com/wp-content/uploads/2009/01/fader.html
Faderitems Class http://www.designscripting.com/wp-content/uploads/2009/01/faderitems.html
FaderURL Class http://www.designscripting.com/wp-content/uploads/2009/01/faderurl.html
FaderFileMaterial http://www.designscripting.com/wp-content/uploads/2009/01/faderfilematerial.html

Find the example source for creating SlideShow using Fader with the source file.

GET THE UPDATES VIA EMAIL

We don't share your email anywhere, grab our rss via feedburner


Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.