Easy Slideshow Component

v1.0
July 3, 2002
darshan sawardekar
darshan@octaneinteractive.com
http://www.octaneinteractive.com/

Requirements :
Macromedia Flash MX,
Easy Slideshow Component, get it here
Intermediate knowledge of flash, and some knowledge of flash MX.

Time Required :
30-60 minutes.

Features :
Create Slideshow of images (jpegs), or swfs. Smoothly transition from one image to another. Choose from a variety of masking styles or create your own masks instead. Your custom masks can be both animated or scripted. Preview : Before we begin, you can take a look at what the slideshow component does here.

Introduction :
Prior to Flash MX, masking was limited to graphic shapes only. However Flash MX introduces the ability to use movieclips as masks as well. This feature of flash MX is exploited to generate the various masking transitions you saw above. The component loads a new file in the background and then removes the mask of the upper image piece by piece to generate the transition. Initially a data file (XML or text) is loaded into the component which parses the data and then goes on to load the current file from the list.

Usage :
Drag the Easy Slideshow component from the components panel to stage. You may resize it as you wish. Then enter the components parameters in the property inspector panel. And you are all set to go.

Parameters :
dataFile :
The absolute or relative URL to your data file. You can load XML data as well as text data into the component. The text data file can come from a server-side script like ASP, PHP, CFML, etc. as well.

E.g. :
Sample data Files can be,
Absolute -
http://www.mysite.com/imageData.xml OR
http://www.mysite.com/data/imageData.asp


Relative -
imageData.xml OR
data/imageData.asp,
depending on the location of your flash movie with respect to the data file

Syntax :
mySlideshow.setDataFile ("http://www.mysite.com/imageData.xml");

dataType :
Specifies whether the dataFile is an XML document or plain text. Please specify the correct dataType for the corresponding dataFile. Note the dataType parameter specifies the data type of the data file, and not the data type of the data inside the data file.

E.g. :
Sample dataTypes, only 2 "xml" OR "txt"

Syntax :
mySlideshow.setDataType ("txt");

pieces :
As explained above the masking transitions are achieved by removing each piece of the overlying mask one by one. The pieces parameter specifies how many pieces constitute the entire mask. Please do not set this parameter too high as it will cause flash to think it is an infinite loop, causing the script to stop responding. The Default value is 20. Masking styles like "dissolve", "stripesDiag", "Sweep1", etc. are processor intensive tasks and should not be used with very high number of pieces. On slower machines pieces above 150-200 can cause slowing down of the movie. You might have to experiment a bit to achieve the right balance.

Also, you might get erroneous lines or stripes depending on you pieces parameter. The individual piece widths and heights for most masking styles is calculated as the ratio,
componentWidth/pieces AND
componentHeight/pieces.
To avoid getting these lines or stripes, try to use pieces which are exactly divide the component width or height.
For component width 200, 20 pieces is okay, but 17 is not.

E.g. :
Default pieces parameter is 20.

Syntax :
mySlideshow.setPieces (40)

maskStyle :
Mask styles are transitions between the currently displaying image and the newly loaded image.

You can choose from these predefined maskStyles, none, fade, dissolve, stripesHorz, stripesVert, stripesDiag, Sweep1, movieclip, random.

none : No transition effect, as soon as the next image is loaded it is displayed on top.
fade : The front image fade out.
dissolve : A rectangular grid is created and pieces are removed from it depending on the pieceRemoval style. Coupled with random piece removal you can get a dissolve animation effect.
stripesHorz : Horizontal stripes are removed from the front image piece by piece, thereby uncovering the next loaded image.
stripesVert : Vertical stripes are removed from the front image pieces by piece, thereby uncovering the next loaded image.
stripesDiag : Diagonal pieces of the front image are removed piece by piece.
Sweep1 : A variation of the stripesDiag style, but removes 3 different pieces simultaneously.
movieclip : Uses your own movieclip as the custom mask that removes piece by piece of the front image. The mcID parameter has to be specified correctly for this to work. More information on creating your own custom masks later.
random : randomly chooses a masking style from the above mentioned styles.

E.g. :
Sample maskStyles "none", "fade", "dissolve", "stripesHorz", "stripesVert", "stripesDiag", "Sweep1", "movieclip", "random" Use lowercase characters for consistency.

Syntax :
mySlideshow.setMaskStyle ("random");

removalStyle :
This parameter indicates the order of removal of the pieces from the mask. The following removalStyles are available : forward, backward, random, adaptive, random-random

forward : pieces are removed in the order that they were created. (FIFO - First in First Out)
backward : pieces are removed in the opposite order that they were created (LIFO - Last in First Out)
random : pieces are removed randomly
adaptive : When navigating to the next image, the forward removalStyle is used and when navigating to the previous image, the backward removalStyle is used.
random-random : A random removalStyle is chosen between the above 4 styles.

E.g. :
Sample removalStyles : "forward", "backward", "random", "adaptive", "random-random"

Syntax :
mySlideshow.setRemovalStyle ("adaptive");

mcID : Specifies the linkage identifier of your customMask movieclip. More information on creating you own custom masks later. 2 Sample custom Masks (pageFlipMask and scriptedMask) can be found in the custom masks folder of the Easy slideshow component.

E.g. :
Same as the linkage identifier you specify for your movieclip in the library.
Syntax :
mySlideshow.setMcID ("pageFlipMask");

fadeStep : The speed with which the front image fades, when using the "fade" maskStyle. A number between 1 and 100 is expected.

E.g. :
any number between 1 & 100.
Syntax :
mySlideshow.setFadeStep (10);

loop : Specifies whether the Slideshow loops after the end of the file list. If specified to true, the slideshow loads the first file after the last file, and the last file after the first file.

E.g. :
a boolean (true or false)
Syntax :
mySlideshow.setLoop (true);

removalDelay : The time to pause before removing the next piece of the mask. This time is specified in milliseconds. The default is 1.

E.g. :
a number, ideally not very large, so that the transition is smooth. autoDelay : The time to pause in autoPlay mode before getting the next file. This time is in milliseconds.

Syntax :
mySlideshow.setAutoDelay (5000); // 5 seconds

playMode :
The direction of play back of the slideshow in autoplay mode. The following playModes are available, forward, backward, random
forward : loads the next file in the file list.
backward : loads the prev file in the file list.
random : randomly load any file in the file list.

E.g. :
Sample values : "forward", "backward", or "random".
Use lowercase characters for consistency.
Syntax :
mySlideshow.setPlayMode ("forward");

loadHandler : The loadHandler function is called every time a file is loaded into the Easy Slideshow component. 3 arguments are passed to the load handler function.
1. An object containing all the attributes of the current file.
2. An array containing the names of all the attributes available.
3. The file ID of the currently loaded file.
The load handler function can be used to display information about the currently loaded file, outside the Easy Slideshow component. More information on using loadHandlers later.

E.g.:
// in the sample (SlideshowPlayer) the loadHandler is updateCaption

Syntax :
setLoadHandler (functionName, containingObject);
// in this case
mySlideshow.setLoadHandler ("updateCaption", _root);

where _root is the containing object. If not specified it defaults to the parent timeline.

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

Here on in the display & formatting parameters are discussed.

stripeH : The height of the Slideshow Preloader. Slideshow preloader is the bar that moves in or out to display preloading information.

E.g. :
30 is Default

Syntax :
mySlideshow.preloader.setHeight (50);

dockTo :
The Slideshow preloader can dock to the top or bottom of the component.

E.g. :
"top" or "bottom"
Syntax :
mySlideshow.preloader.setDock ("top");

fontFace : the font face used in the Slideshow preloader.

E.g. :
Any font face, embedded or otherwise.
Syntax :
mySlideshow.preloader.setFontFace ("Arial");

fontSize :
the font Size used in the Slideshow preloader
E.g. :
a number, default is 14
Syntax :
mySlideshow.preloader.setFontSize (8);

fontColor :- a string specifying the font color.

E.g. :
"#FF0000" // red
Syntax :
mySlideshow.preloader.setFontColor ("#FF0000");

fillColor :
The color of the stripe of the Slideshow Preloader. Hex Number expected.
E.g. :
0x00FF00 // green
Syntax :
mySlideshow.preloader.setFillColor (0x00FF00);

faceColor :
The color of the face of the Easy Slideshow Component. Since no image is initially loaded into the slideshow, you can set it to the background color to create a smooth transition, for the first file as well.
E.g. :
0x0000FF // blue
Syntax :
not needed

embedFonts :
A boolean that specifies whether the Slideshow preloader uses embed fonts or not.
E.g. :
a boolean (true of false)
Syntax :
not needed

showBytes :
specifies whether the bytes are shown or not.
E.g. :
a boolean (true or false)
Syntax :
mySlideshow.preloader.setShowBytes (true);

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

Snapshot of all parameters :

Parameter
Description / Values
Syntax
dataFile Your data file URL mySlideshow.setDataFile (dataFile)
dataType xml/txt mySlideshow.setDataType (dataType)
pieces number, not very high mySlideshow.setPieces (pieces)
maskStyle none, fade, dissolve, stripesHorz stripesVert, stripeDiag, Sweep1, movieclip, random mySlideshow.setMaskStyle (maskStyle)
removalStyle forward, backward, random, adaptive, random-random mySlideshow.setRemovalStyle (removalStyle)
mcID movieclip linkage identifier mySlideshow.setMcID (mcID)
fadeStep a number between 1 & 100 mySlideshow.setFadeStep (fadeStep)
loop true / false mySlideshow.setLoop (loop)
removalDelay time delay between piece removal mySlideshow.setRemovalDelay (removalDelay)
playMode forward, backward, random mySlideshow.setPlayMode (playMode)
loadHandler handler function triggered when a file is loaded mySlideshow.setLoadHandler (func, path)
stripeH preloader stripe height (a number) mySlideshow.preloader.setHeight
dockTo top / bottom mySlideshow.preloader.setDock
fontFace font face mySlideshow.preloader.setFontFace
fontSize font size mySlideshow.preloader.setFontSize
fontColor font color mySlideshow.preloader.setFontColor
fillColor preloader stripe color mySlideshow.preloader.setFillColor
faceColor Easy slideshow start face color not needed
embedFonts true / false not needed
showBytes true/ false mySlideshow.preloader.setShowBytes

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

How To create the data file :
You can load 2 types of data files into the Easy slideshow component, namely xml and text. These files can come from any server-side scripting language as well. The data file contains the following information :
1. totalFiles in the file list
2. currentFile (first file) to load into the slideshow.
3. total attributes of each file. (URL attribute is necessary)
4. URL attribute indicates the location of that file. If relative, it should correspond to the location of the slideshow movie.
5. Other attributes of each individual file, like title, description, etc.

Structure of the XML dataFile :
The basic structure of the xml file should be :

<files totalfiles="2" currentFile="2">

</files>

This file indicates that, there are 2 files in the file list and each file has one attribute of name "URL". Also each file element has the corresponding "num" attribute that indicates the number of that file in the file list. Also note currentFile attribute is "2", indicating that the slideshow should load the 2nd file first. The location of the individual file is given by the respective URL elements of the file element,
i.e.:- myImage1.jpg and myImage2.jpg.

Structure of the Txt dataFile :
We use &br= as a pseudo line break to display the data better.
The basic structure of the data file should be

&totalFiles=2&br=
&currentFile=2&br=
&totalAttributes=1&br=
&attribute1=URL&br=

&file1URL=myImage1.jpg&br=
&file2URL=myImage2.jpg


This file indicates simply indicates
totalFiles = 2,
currentFile = 2,
totalAttributes = 1
attribute1 = "URL"

Here we name the first attribute as "attribute1" itself. Similarly, we provide the URL of the first file as file1URL (as in file + num + attributeName). If we had another attribute say, title, we would say, file1Title respectively.

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

That's all the data you need to get the Slideshow to work.

Working with the loadHandler :
As mentioned earlier, when the a file is loaded into the slideshow, the loadHandler function is called. The load Handler is passed the current file's attributes in the first argument in the format.

{ }

So in this case, it will pass only the URL as {URL : "myImage1.jpg"} for the first file.

The second argument passed will be the attributes array
[attributeName1, attributeName2, ...]

So in this case, it will be ["URL"], since there is only one attribute, in our data File.

The third argument passed is loadID. This specifies whether the currently loaded file is a "data" file containing the file list or the actual file that is a part of the transition. Its returns "file" only. Where would this be useful?

The Easy Slideshow component has a method, getAllAttributes ();

This method returns an object that resembles the structure of you data file.
Since attributes won't be loaded until the data file has loaded, you can check in the loadHandler if the the 3rd argument is "file", and only then call the getAllAttributes () method. The structure of the object in this case would be,

{
}


Using this object you can build data to supply to other components, like a comboBox component. The sample file does exactly this. Using this you can further extend the Easy slideshow component into a general purpose website interface!

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

Creating the Slideshow navigation :

The Easy Slideshow Component has the following navigation based methods, using which you can load any file from the file list into the slideshow component. The methods are

Method
Description
Syntax
getFile gets the corresponding file mySlideshow.getFile (cmd, fileNum)
startAutoPlay starts autoPlay mode in the Slideshow mySlideshow.startAutoPlay ();
stopAutoPlay stops autoPlay in the Slideshow mySlideshow.stopAutoPlay ();
doLoadData starts loading the dataFile. By default the slideshow will immediately start loading the dataFile. mySlideshow.doLoadData ();

getFile :
starts loading the corresponding file into the the slideshow component. Takes 2 parameters cmd, and fileNum

cmd can have these values : next, prev, first, last, current

next : loads the next file in the file list. If loop is true it will go to the last first file after the last file.

prev : loads the previous file in the file list. If loop is true it will load the last file after the first file.

first : loads the first file in the file list.

last : loads the last file in the file list.

For the above 4 values, the getFile methods does not need the second parameter.

current : loads the current file in the file list. The second parameter fileNum, specifies which file to load. Using this method the jumpMenu has been created inside the sample file(SlideshowPlayer).

Note due to the nature of the masking transitions, during a transition any calls to getFile method, will be ignored. However getFile method is available even when another file is loading.

E.g.:
// gets the next file
mySlideshow.getFile ("next");

// gets the previous file
mySlideshow.getFile ("prev");

// gets the first file
mySlideshow.getFile ("first");

// gets the last file
mySlideshow.getFile ("last");

// gets the 2nd file in the file list
mySlideshow.getFile ("current", 2);

startAutoPlay :
starts autoPlay mode in the Easy Slideshow component. The time delay depends on the autoDelay parameter, which can be set with, mySlideshow.setAutoDelay (10000), // 10 seconds

E.g. :
mySlideshow.setAutoDelay (5000);
mySlideshow.startAutoPlay ();

makes the slideshow load a new file every 5 seconds.


stopAutoPlay :
stops autoPlay in the Easy Slideshow Component.

E.g. :
mySlideshow.stopAutoPlay ();

Note : When the getFile method of the Slideshow is called, autoPlay is automatically stopped.

doLoadData :
starts loading the dataFile in the Easy Slideshow component.

E.g.:
//set the dataType to "xml"
mySlideshow.setDataType ("xml");

//set the dataFile to "newData.xml"
mySlideshow.setDataFile ("newData.xml");

//and load this new data
mySlideshow.doLoadData ();


Will load the data in the newData.xml, and them load the current File in that file list, while still maintaining the masking transition.

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

Creating your own movieclip masks (customMasks) instead of the provided masking styles :
You can created animated masks as well as use the drawing API of flash MX to create your custom masks.

Animated (Non - Scripted) masks :
Create an empty movieclip symbol, inside flash MX, and give it a linkage identifier say "myMask". add a dummy graphic on the stage. Now add the following script in to the first keyframe.

stop ();
component = this._parent._parent._parent;
this._width = component.w;
this._height = component.h;
gotoAndPlay (this.currDirection);


This makes the mask scale to the slideshow width and height.

If you want to use adaptive pieceRemoval you will need to create both forward and backward animations. now add labels, "forward" and "backward" to the timeline, depending on how long your animation is. Starting with the forward label create you animation. Remember you are making a mask animation, so you need something that masks fully and slowly reduces in size, until there is no mask at all.

On the keyframe after the mask is over, enter the script,

stop ();
component.clearLag ();

This tells the component that your custom mask is complete.

Similarly, create the "backward" animation. Same principle again full mask to no mask. and on the next keyframe after the mask enter the same script.

stop ();
component.clearLag ();


Note : the dummy need not be present on the mask after the first frame. For further reference look at the pageFlipMask movieclip in the custom masks folder.

Scripted Masks :
You can also use the new Drawing API to create the custom Mask. Create a new movieclip symbol and give it a linkage identifier "myScriptMask" Create a dummy graphic on the first frame, convert it to a movieclip and give it instance name, dummy. Add the following code to the script on first key frame.

component = this._parent._parent._parent;
mc = this._parent._parent;
dummy._width = component.w;
dummy._height = component.h;


Here you resize the dummy instead of the whole stage, because you want to preserve the xscale and yscale of the mask. to draw the mask you will need 3 parameter from the component, namely w -- > width h --> height pieces --> pieces To get them simply use,

component.w,
component.h,
component.pieces,

respectively.

The procedure you have to follow is, create a new Movieclip, save a reference of it in the array, mc.arrPieces, and draw inside it with the drawing API, In this manner populate the whole stage with the mask. and then call,

component.startClearing.call (component);

like this. This tells the component to start clearing the pieces from the mask. Look at the scriptedMask movieclip inside the customMasks folder for further reference. Note : for consistency, I have added 3 labels "forward", "backward", "random", to this mask to make it compatible with general customMasks.

After you have created your custom mask, you can change the maskStyle parameter to "movieclip" and set mcID to your movieclip's linkage identifier, to start using your custom mask.

»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

Modifications :
1. Although the primary purpose of the component is to create a slideshow, you can easily create other website interfaces around it, with the getAllAttributes () method.
2. Since swfs can be loaded into it, any thing that you can do with swfs, can be done here.
3. You could even load an swf containing a slideshow component into it!!!
4. Although this component loads images only when requested, using the Slideshow preloader component a chain to preload the images first could be easily created.

Bugs / Issues :
1. You cannot mask non-embedded or device fonts. However at the time of writing this tutorial, macromedia has released a beta player (v 6.0.39.0) that allows masking of devices fonts/non-embedded fonts. However you still cannot use device or non-embedded fonts as masks. But alpha transparency is still not available to device fonts. To be sure try not to use device fonts on the masking frame, for effects like fade, sweep1 or your customMasks

2. Flash movie stops responding. This is caused due to using very high piece parameter inside Easy slideshow component. As explained earlier, Transition effects like dissolve, sweep1, stripesDiag, etc. are processor intensive tasks. To avoid slowing down the system, do not set the pieces parameter very high.

3. Slideshow does not get the new file, when a transition is occurring. This is not a bug! The masking is based on creating individual movieclips that mask the image. Hence depths have to be preserved. To do so the slideshow won't be accessible during the transition. However it is accesible even a file is loading.

4. Any other bugs / issues are welcome.

Documentation / Samples:
If you installed the .mxp , full documentation is available in the reference panel of Flash MX. Also a samples folder would be created containing the SlideshowPlayer.fla sample, the data files, and the files in the sample data file. On windows 2000 or XP, this folder would be located at,

C:\Documents and Settings\<your computer name>\Application Data\Macromedia\Flash MX\Configuration\Samples

If you can't find the files, you can download them here.

Finally, you may use this component for personal or educational purposes as you please, as long as clearly visible credit is given. Please contact me for commercial use.