This file is a demo of a sliding images gallery, as used on my work site, http://www.thereformation.co.nz.
Basically images are loaded sequentially from an XML file into a movieClip, which is dynamically masked and then tweened. The gallery has support for text descriptions and also creates a dynamic image numbers navigation system which updates itself based off how many images you happen to load in. All text is CSS styled.
Contained in the .zip file are a Flash CS3 and Flash 8 source file, XML files, sample images, the tweenFilterLite class and the font used in the project.
Updates
09 June, 2008. File now supports multiple XML files
View Example
View an example of the project here; http://noponies.com/dev/slideimages/ (no preloader, 36k file size)
Source Files
Grab source files here; Sliding Images Gallery Source
Dependencies
TweenFilterLite http://www.tweenlite.com
Flash CS3 or Flash 8
ActionScript Source
/************************************************************************
NOTES
This file works with fixed image sizes! I attaches the image holding MC "imageHouse" from the
library along with the navigation text MC, "navHolders". Text links are added to this MC by
attaching the "SampleLinks" mc. These MCs are attached like so, so that the navHolders MC can
be tweened easily, if need be.
The main images are simply a movieClip with a mask. The images are loaded in into the background of
the "imageHouse" clip, which is then tweened to create the sliding image movement. The mask is created
via actionScript and bases its dimensions off the size of the first bit of loaded large image content.
The large images have text fields, drawn in from the XML file. Simple remove references to this, if you
do not want text descriptions.
The text is CSS styled.
The font used is Minion. Included in file.
There is no formal preloader for each large image. But the progress handler exists, its just not hooked into
in the script.
I requires the http://www.tweenLite.com AS2 TweenFilterLite class files.
by noponies, 2008
http://www.blog.noponies.com
************************************************************************
DONATE
************************************************************************
Consider donating to pay for the hosting and development time of this file.
https://www.paypal.com
************************************************************************/
//init global variables and properties
Stage.scaleMode = "noscale";
import gs.TweenFilterLite;
import gs.TweenLite;
stop();
/************************************************************************
LOAD STYLE SHEET FOR DESCRIPTIONS TEXT
************************************************************************/
var styleObj:TextField.StyleSheet = new TextField.StyleSheet();
styleObj.onLoad = function(success:Boolean) {
if (success) {
//nada
}
};
styleObj.load("styles.css");
/************************************************************************
LOAD XML
************************************************************************/
var slide:XML = new XML();
slide.ignoreWhite = true;
var urls:Array = new Array();
var captions:Array = new Array();
var imageName:Array = new Array();
//not used
var p:Number = 0;
//positional Array Index tracker
slide.onLoad = function() {
urls = []
captions = []
imageName = []
xmlNode = this.firstChild;
var photos:Array = this.firstChild.childNodes;
for (i=0; i<photos.length; i++) {
urls[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
imageName[i] = xmlNode.childNodes[i].childNodes[1].lastChild.nodeValue;
captions[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
}
p = 0;
loadLarge();
//load the large images
};
slide.load("slideimages.xml");
//attach the main content holder MC
//delete this attachMovie if you want to have a MC sitting on the stage, manually added. Just make sure it has
//the instance name "imageHolder_mc"
this.attachMovie("imageHouse", "imageHolder_mc", this.getNextHighestDepth(), {_x:7, _y:163});
//attach the nav holder movieClip, remove this if you don't want nav text...
this.attachMovie("navHolders", "navHolder_mc", this.getNextHighestDepth(), {_x:7, _y:120});
//Slider vars
var offset:Number = imageHolder_mc._y;
//pos of image holder movieClip
var imageNavPunctuation:String = ",";
//imageNavPunctuationuation string, for dynacmically attached image numbering
var butNavCounter:Number = 0;
//used by the next image button...
var pos:Number = 0;
//vertical increment value, based off each images height
var navPos:Number = 0;
//start pos of image navigation links
/************************************************************************
LOAD LARGE IMAGES
************************************************************************/
function loadLarge() {
var container:MovieClip = imageHolder_mc.attachMovie("ImageHolder", "ImageHolder"+([p]), imageHolder_mc.getNextHighestDepth(), {_x:0, _y:pos});
//images
var navContainer:MovieClip = navHolder_mc.attachMovie("sampleLinks", "sampleLinks"+p, navHolder_mc.getNextHighestDepth(), {_x:navPos, _y:0});
//image nav text
var Clip:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
var target_mc = container;
//indicate loading in of work samples and attach mask of the content
if (p == 0) {
//create a mask for the image content, based off position of imageHolder_mc
container._parent._parent.createEmptyMovieClip("imageMask_mc", 400);
//_root timeline
imageMask_mc.beginFill(0xFF0000, 0);
imageMask_mc.moveTo(imageHolder_mc._x, imageHolder_mc._y);
imageMask_mc.lineTo(imageHolder_mc._x+imageHolder_mc._width, imageHolder_mc._y);
imageMask_mc.lineTo(imageHolder_mc._x+imageHolder_mc._width, imageHolder_mc._y+imageHolder_mc._height);
imageMask_mc.lineTo(imageHolder_mc._x, imageHolder_mc._y+imageHolder_mc._height);
imageMask_mc.lineTo(imageHolder_mc._x, imageHolder_mc._y);
imageMask_mc.endFill();
imageHolder_mc.setMask(imageMask_mc);
}
mclListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
load_txts.text = "Loaded "+ bytesLoaded + " bytes of " + bytesTotal +" of image number "+(p+1);
};
mclListener.onLoadInit = function(target_mc:MovieClip) {
//indicate how many images to load
details_txts.text = "Fetched "+(p+1)+" of "+(urls.length)+" Images";
//handle the numbering of mc's, this function removes the final comma
if (p == urls.length-1) {
imageNavPunctuation = "";
}
//text details in imageHolder
container.imageDetails_txt.styleSheet = styleObj;
//css style
container.imageDetails_txt.htmlText = captions[p];
//add text description
//set up the nav text
navContainer.nav_txt.text = p+1+imageNavPunctuation;
//add 1 to remove leading 0 from array index
navContainer.nav_txt.autoSize = "left";
//autosize the samples text
/************************************************************************
NAVIGATION BUTTONS
************************************************************************/
navContainer.onRollOver = function() {
TweenLite.to(this, .2, {_alpha:50});
};
navContainer.onRollOut = function() {
TweenLite.to(this, 1, {_alpha:100});
};
//handle a click on the navigation text
navContainer.onRelease = function() {
//here we check to see what numbered button a user has pressed
//we take one off the parseInt result because we added a 1 earlier, when we set up the button nav..
targetLoc = (parseInt(this.nav_txt.text))-1;
//convert the text clicked on into an integer, -1. This gives
//us a number to use in the below equation for calculating how far to slide the images to.
TweenLite.to(imageHolder_mc, 1, {_y:-(container._height*targetLoc)+offset, ease:Strong.easeOut});
};
/************************************************************************
IMAGES
************************************************************************/
target_mc.onRollOver = function() {
TweenFilterLite.to(target_mc, .4, {type:"Color", saturation:0, ease:None.easeOut});
};
target_mc.onRollOut = function() {
TweenFilterLite.to(target_mc, 1, {type:"Color", saturation:1, ease:None.easeOut});
};
//increment counter variable
p++;
//function checking section, are we done loading?
if (p<urls.length) {
pos = pos+container._height;
//increment image height.
navPos = navPos+navContainer._width-8;
//space the nav text, this spacing allows for this text to contain more than one digit
//recursive call to same function, runs only as many times as there are images
loadLarge();
}
if (p == urls.length) {
details_txts.text = "";
load_txts.text = ""
//clear loading message
slideImages_btn._visible = true;
//turn on nav button
loadNewGallery_btn._visible = true;
}
};
Clip.addListener(mclListener);
Clip.loadClip(urls[p], container.sample);
}
/************************************************************************
SLIDE IMAGE BUTTON
************************************************************************/
slideImages_btn._visible = false;
//turn it off to all is loaded
slideImages_btn.onRelease = function() {
butNavCounter++//increment the counter variable, we set this to be 0 initially, which is the first image, so we add 1 to the start, to get
//to the next image with the first click
TweenLite.to(imageHolder_mc, 1, {_y:-(imageHolder_mc.getInstanceAtDepth(1)._height*butNavCounter)+offset, ease:Strong.easeOut});
//reset the counter var to create a loop. Note that we are setting it to -1, so that when this function runs again, butNavCounter becomes 0, which
//is the first image
if(butNavCounter== urls.length-1){
butNavCounter = -1
//butNavCounter = urls.length-1 //for making the image stop at the last one
//this.enabled =false //turn off the button if you stop the slides, good UI practice!
}
};
/****************************************************************************
REMOVE ALL CONTENT METHOD
****************************************************************************/
//Use to clear old images if you are going to add in a new set of images
function removeSlides():Void {
for (var i in imageHolder_mc) {
if (typeof (imageHolder_mc[i]) == "movieclip") {
removeMovieClip(imageHolder_mc.getInstanceAtDepth(imageHolder_mc[i].getDepth()));
}
ImageHolder._height = 0;
imageHolder_mc._y = offset;
p = 0;
pos = 0;
}
}
function clearTextNav():Void {
for (var i in navHolder_mc) {
if (typeof (navHolder_mc[i]) == "movieclip") {
removeMovieClip(navHolder_mc.getInstanceAtDepth(navHolder_mc[i].getDepth()));
}
butNavCounter = 0;
navPos = 0;
}
}
/****************************************************************************
ADD IN NEW GALLERY
****************************************************************************/
loadNewGallery_btn._visible = false;
loadNewGallery_btn.onRelease = function() {
removeSlides()
clearTextNav()
slide.load("slideimagesa.xml");
};