Content updates in Flash can be difficult and time consuming due to the many steps involved. Simply reading content from an XML file means that importing new assets and recompiling the swf is no longer necessary. This tutorial will cover dynamically loading images from an XML file and then deal with inconsistencies in image dimensions using the GreenSock Tween Max animation library.
Final Result Preview
Let’s take a look at a screenshot of the final slideshow we will be working towards:

Background
Interface images and examples are provided using Flash CS4 and Actionscript 2 but other versions of Flash as far back as version 8 should be able to follow along without problems. This tutorial assumes at least a working knowledge of Actionscript since I’m not going to explain every line, however even if you simply copy and paste you should be able to get this to work.
Step 1 – Create a Project Folder
With a project of this type it’s important to keep everything organized so that Flash can find things as it needs them. So create a project folder on your computer where you can place ALL the files related to this project.
Step 2 – Prep the Assets
Find images for your slideshow. I used several images from http://www.sxc.hu (sxc_hu_410471_5588.jpg, sxc_hu_1151936_79441078.jpg, sxc_hu_1152040_85122875.jpg, sxc_hu_1154131_54136948.jpg).
Create an “assets” folder inside your project folder. Open up your favorite image editor and resize your photos so they’re all a similar size. I resized my images so that the longest side (height or width) is 700px and allowed the image editing software to maintain the image proportion.
Since external assets don’t benefit from a Flash preloader this would be an excellent time to optimize your images for speedy downloads. Flash can load png, jpeg, or gif files so make sure your final images are in one of those formats and save them into the assets folder you just created.
Step 3 – Create a New Actionscript 2 Flash File

Step 4 – Setting Up The Stage
Resize your stage to be a little larger than the images you created in Step 2. The goal is to make sure that what ever images are displayed don’t get cut off in the final presentation. I used 800px x 800px to give the 700px images 50px of space on all sides. Now is also a great time to change the frame rate to 30fps for nice smooth transitions and pick a background color of your choice.

Step 5 – Setting Up The Timeline
Rename “layer 1” to “background”. Create a new layer and call it “content”. Create one more layer and call it “script” and it’s a good idea to lock this layer. Anything you place on the background layer will display behind the slideshow. If you look at the example, the text is in this layer.

Step 6 – Create a Shell For The Loaded Images
Use the drawing object to create a white square on the stage. Select the square and convert it to a symbol (F8). Make sure the registration point is in the top left corner and call the clip “shell”. Give the clip an instance name of “shell_mc”.


Step 7 – Add the Photo Background
Inside “shell_mc” select the white box and convert it to a symbol (F8). Again, make sure the registration is in the top left and name the clip “background”. Give the new movieClip an instance name of “background_mc”. Lastly, name the layer "background" and lock it.
Step 8 – Create Loading Text
Inside “shell_mc” create a new layer called “text”. Use the text tool to create static text that says “loading image”. Move the text to x:20 and y:20 so that it ends up underneath the image.
Step 9 – Add an Image Load Target
Create another new layer inside “shell_mc” called “images”. Create a blank movieClip called “pics” then drag it from the library to the newly created "images" layer. Move the clip to x:10 and y:10 and give it an instance name of “pics_mc”.
Step 10 – Create a Shape to Mask the Image
Inside “shell_mc” create a layer above “images and name it “mask”. Make a new square, convert it to a movieClip called “mask” and give it an instance name of “mask_mc”. Move the clip to x:10 and y:10.
Step 11 – Convert the Shape to a Mask
Right click on the “mask” layer and select Mask. Make sure that the “mask” and “image” layer icons change to look like the example.

Step 12 – Create an Image Frame
Inside “shell_mc” create a layer above “mask” and name it “frame”. In the tool palette, select a stroke color and a different fill color, then create a square on the “frame” layer. Select the fill area and delete it leaving only the border. Double click the border to select it and convert it to a movieClip called “border”. Give the movieClip and instance name of “border_mc” and place it at x:10 and y:10.

Step 13 – Add a Drop Shadow
Go back to the root timeline and select “shell_mc”. Go to the properties panel and twirl down the Filters arrow. Click the small “page” icon and select drop shadow. This will add a little depth.

Step 14 – Create XML File and Add Structure
We’re done with Flash for the moment and need to create an XML file to keep track of our pictures. Open your favorite text editor (pretty much anything that can edit HTML will work) and create a new file. Save the file in your project folder as content.xml. Now we need to add a structure to the file so Flash can understand how to use the information, we can do that with the following code:
<?xml version='1.0' encoding='UTF-8'?> <gallery></gallery>
Step 15 – Add Image Paths to XML File
Now we need to add paths to all the images in the slideshow (this is how Flash is going to “find” the images). Inside the <gallery> tags add a new tag called “image” and give it an attribute of “imgurl”. This attribute should equal an image path relative to the xml file. You’ll need to create a new “image” tag for each image you plan to use in the slideshow.
<?xml version='1.0' encoding='UTF-8'?> <gallery> <image imgurl="assets/sxc_hu_410471_5588.jpg"></image> <image imgurl="assets/sxc_hu_1151936_79441078.jpg"></image> <image imgurl="assets/sxc_hu_1152040_85122875.jpg"></image> <image imgurl="assets/sxc_hu_1154131_54136948.jpg"></image> </gallery>
Save the file and close your text editor.
Step 16 – Download Tween Max
We’re going to use a tweening library to help us animate the transitions between images, so open up your browser, go to http://blog.greensock.com/tweenmaxas2/ and click the "download AS2" button at the top. Open the zip file you downloaded, then copy the "gs" folder and its contents to your project folder.
It’s time to go back to your Flash file and start writing some Actionscript. Select the first frame of the "script" layer and open the Actions Panel (Window > Actions). The following steps all require you to edit the contents of the Actions window, so from now on I’m simply going to refer to this as "script". As we go through the steps below you’ll see all the script created to that point with the newest additions highlighted.
Step 17 – Include Tween Max
The first thing we need to do is include the tween class we downloaded so that it compiles when the swf is created. Add the following code to your script:
import gs.*; import gs.easing.*;
Step 18 – Tell Flash to Load the XML File
(Additional lines: 3-15)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
} else {// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
photos_xml.load(xmlPath);
This is creating a new XML object that targets our "content.xml" file. Since XML files don’t load instantly, it’s important to check for a completed load. We do this with the onLoad callback that waits for the xml file to be loaded and then performs an action.
Step 19 – Convert XML Data to an Array
First we need to create an array called "imageList". Once the xml file has loaded, we’re going to assign the data to the array so that it’s easier to access later.
(Additional lines: 7,10)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
photos_xml.load(xmlPath);
Step 20 – Build Movieclip Loader Framework
Create an image loader object using the movieClipLoader class and use call backs to initiate commands when the movie starts/finishes loading.
(Additional lines: 17-27)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
}
photos_xml.load(xmlPath);
Step 21 – Create a Load Function
After the loader object exists we need a function to determine the correct images. We also have to add a variable to keep track of the current image. Inside the "loadImage" function the "loadURL" is set to the XML attribute for the image path. Define a new movieClip (targetClip) for a container to load the image into and set that container to have zero opacity with the _alpha property.
The last step in the function is to load the image into the container (imageLoader.loadClip). We also want to run the "loadImage" command as soon as the XML has successfully finished loading.
(Additional lines: 11,18,31-38)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
// load the new image
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 22 – Add a Timer Using the setInterval Function
Build a timer function that will call the "loadImage" function every 5000 miliseconds (5 seconds). Initiate the timer when when the image has completed loading, by placing the call in the onLoadComplete callback.
(Additional lines: 29,32-34)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 23 – Resize the Image Frame
We need to resize the "background_mc", "border_mc" and "mask_mc" to be the size of the loaded image. The TweenMax/TweenLite library is pretty easy to use. The syntax is TweenLite.to(target clip, time in seconds, {properties:value, ease type}); We also want the image to fade in after it has loaded, so set the _alpha to tween to 100% inside the onLoadComplete.
(Additional lines: 25-27,31)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function removePrevious(){
if(prevImg != undefined){
removeMovieClip(prevImg);
}
// increment the current image
if(currentImage < imageList.length -1){
currentImage = currentImage + 1;
}else{
currentImage = 0;
}
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 24 - Center the Image
First find the center of the stage by dividing the stage height by 2 and the stage width by 2. Next, since the registration point of the shell is in the top left, move the clip to the left of the center of the stage by half the shell's width and up by half the shell's height (variables clipXTarg and clipYtarg calculate the numbers for each new image). Its important to use the Math.round() function so that the final number doesn't contain a decimal - this forces the final position to a full pixel.
(Additional lines: 28-30)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 25 - Identify the Previous Image
We need to find the previously loaded image so that it can be removed. Obviously if the current image is some where in the middle of the list then the previous image is one less than the curentImage number. However, if the currentImage is equal to zero then the previous image (assuming the slideshow has stepped through every image) would be the last image in the array or imageList.length - 1. Take the previous image number and figure out the movieClip path to the previous image shell.
(Additional lines: 32-37)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
if(currentImage == 0){
var prevImgNum = imageList.length -1;
}else{
var prevImgNum = currentImage - 1;
}
var prevImg = shell_mc.pics_mc["pic"+prevImgNum];
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 26 - Fade Out and Remove
Next we want to fade out the previous image and then when it gets to zero _alpha we need to remove the clip from the stage entirely. The onComplete:removePrevious waits until the fade has completed and then calls a the "removePrevious". As a safety measure its always a good idea to make sure that the clip we're trying to remove actually exists. Therefore use an "if" statement to check that the clip is not undefined (Flash's word for doesn't exist).
(Additional lines: 38,50-54)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
if(currentImage == 0){
var prevImgNum = imageList.length -1;
}else{
var prevImgNum = currentImage - 1;
}
var prevImg = shell_mc.pics_mc["pic"+prevImgNum];
TweenLite.to(prevImg, 0.25, {autoAlpha:0, onComplete:removePrevious});
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function removePrevious(){
if(prevImg != undefined){
removeMovieClip(prevImg);
}
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 27 - Next Image in the Sequence
Now we need to increment the currentImage so that when the timer completes, Flash knows which image to load next. Just like the previousImage, if the current image is any number except the last image in the list we simply add one to the currentImage number. However, if the current image is the last item in the list then the "next" image would start the list over with the first image in the list (position zero in the array).
(Additional lines: 55-59)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
if(currentImage == 0){
var prevImgNum = imageList.length -1;
}else{
var prevImgNum = currentImage - 1;
}
var prevImg = shell_mc.pics_mc["pic"+prevImgNum];
TweenLite.to(prevImg, 0.25, {autoAlpha:0, onComplete:removePrevious});
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function removePrevious(){
if(prevImg != undefined){
removeMovieClip(prevImg);
}
if(currentImage < imageList.length -1){
currentImage = currentImage + 1;
}else{
currentImage = 0;
}
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 28 - Remove the Timer
Most Actionscript functions occur almost instantly, however loading images requires some amount of time. This amount of time depends on the network connection speed and image size and could therefore be several seconds long. We need to remove the timer until the image has finished loading so that the slide show is a consistent length of time after the image has loaded. One simple line of code (clearInterval) removes the 5 second interval until it is reset by the setInterval running again.
(Additional line: 66)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
if(currentImage == 0){
var prevImgNum = imageList.length -1;
}else{
var prevImgNum = currentImage - 1;
}
var prevImg = shell_mc.pics_mc["pic"+prevImgNum];
TweenLite.to(prevImg, 0.25, {autoAlpha:0, onComplete:removePrevious});
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function removePrevious(){
if(prevImg != undefined){
removeMovieClip(prevImg);
}
if(currentImage < imageList.length -1){
currentImage = currentImage + 1;
}else{
currentImage = 0;
}
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
clearInterval(timer);
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
Step 29 - Stop the Timeline
Finally, we need to stop the timeline. Flash's default function is to play the timeline continuously unless told otherwise. In the case where there is only one frame on the timeline Flash will continue to attempt to run the same code over and over again, resulting in the same image trying to repeatedly load.
(Additional line: 72)
import gs.*;
import gs.easing.*;
var xmlPath = "content.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ----------- load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ----------- problem loading, check path
trace("Error loading photos_xml");
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
if(currentImage == 0){
var prevImgNum = imageList.length -1;
}else{
var prevImgNum = currentImage - 1;
}
var prevImg = shell_mc.pics_mc["pic"+prevImgNum];
TweenLite.to(prevImg, 0.25, {autoAlpha:0, onComplete:removePrevious});
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function removePrevious(){
if(prevImg != undefined){
removeMovieClip(prevImg);
}
if(currentImage < imageList.length -1){
currentImage = currentImage + 1;
}else{
currentImage = 0;
}
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip("pic"+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
clearInterval(timer);
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
stop();
Conclusion
Test your movie (Command + Enter for the Mac, Ctrl + Enter for Windows). You should see a working slideshow that resizes and centers based on the size of the images. I hope you enjoyed following this tut!



Ey gracias viejo. Funciona de marvilla.
looks great, but I have this problem using Flash CS4:
Quad.as, line 1
ERROR 5007: An ActionScript file must hav at least an externally vissible definition
does anyone know how to make the image cycle in this code random?
any luck on the random? What about a contoller to pause and go forward and back?
great tutorial, just wondering if anyone knew about adding controls, so rather then taking 5 seconds to load next image, the user could just use a next and previous button?
any ideas please let me know, would be greatly appreciated
From the wisdom of various Flashtuts+ authors we’ll be covering many aspects of slideshows in the coming months, stay tuned! (and keep the suggestions coming ;-))
You can make a function that increases or decreases “currentImage” counter …
function next(){
currentImage++;
loadImage();
}
function previos(){
currentImage–;
loadImage();
}
And modify the loadImage function of course ;)
i would like to add a link on every images… is it possible?
thanks a lot
It would be better if it is in as3 but nice work
This tutorial worked out great for me. Struggling for days until I came across it. AS3 would have been nicer, but you wont hear a complaint out of me =)
For those of you asking about a pause feature, add two simple buttons. (pause_mc, and play_mc)
heres the code i added.
pause_mc.onRelease = function() {
clearInterval(timer);
pause_mc._visible = false;
play_mc._visible = true;
};
play_mc.onRelease = function() {
timer = setInterval(loadImage, 500);
pause_mc._visible = true;
play_mc._visible = false;
};
How would you go about adding the actionscript for back function?
I’m pulling my hair out here! Any help would be incredibly appreciated.
A simple decrement didn’t work for me…
Anyone good enough to help me with a back button? Any help would be super appreciated!
i can’t open the preview.fla – don’t have cs4…can you send me a cs3 version?
Hello Guys.
I’ve took courage to update a script a little to add a captions, if you don’t mind:) It’s not perfect, but at least I try:)
So here it goes.
Create two text boxes (“pos_txt” (this one to display current image out of all images) and “cap_txt” to display a captions).
In ACTION window right before “// increment the current image” text insert these lines:
var my_caption = imageList[currentImage].attributes.Caption;
pos_txt.text = currentImage+1+” / “+imageList.length;
cap_txt.text = my_caption;
and update “content.xml” file in such order
Hope that someone will find it useful.
P.S. All credits still go to Bryce Howitson. If I brake any role with this message, please feel free to delete it. Thanks.
Very helpful Tomas, thanks! Shall definitely be including that.
If anyone can send me any pointers on how to make a back button work I would be thoroughly grateful. I’ve tried for a few days now but using the prevImage variable seems to not work, even though I can trace out the correct index of the array for it all to work, still it behaves strangely. I’m sure it’s my own stupidity but I’m close to giving up and going back to basics without the lovely fade this script has… Any help would be super. Cheers in advance, Alex
it’s nice! thanks Thomas!
ups. sorry, it seems I lost one line in my previous post.
“content.xml” should be updated in this manner
“”
hope this will make it work:)
man, … sorry :) something seems to not post right. Any ways, in contect.xml update lines inserting “Caption=”YOUR TEXT HERE” after “image imgurl=”xxx”"
“image imgurl=”assets/01.jpg” Caption=”YOUR TEXT HERE”></image”
And yes, action and button to go back would be super awesome as well. I couldn’t make it myself:P
please, can someone help making PREVIOUS and NEXT buttons to work with this script? I spent over 4 hours and didn’t succeed:(
any help?
hi,please give me sourse of flash cs3
why AS2 appear at Flash tuts, it should only contain AS3, coz AS2 will be drop by majority ActionScript Code
I am looking for a way to add text to this. An image description.
First of all great tutorial.
Secondly I would like to join Alex and several other users asking how to get working back and forward buttons implemented into this.
It would really help me a lot…
Excellent Tutorial!
Can someone help me randomize the order of the images, but not repeat?
Thanks in advance.
I figured it out with lots of searching on the internet. The answer was to add the following two lines below the line:
imageList = photos_xml.firstChild.childNodes;
imageList.sort(function(){return Math.floor(Math.random()*3)-1});
imageList.pop();
These lines essentially randomizes the xml data as it is loaded into the array and keeps the slideshow from repeating any images.
Hope this helps someone else!
Whoever you are, Jason, if you ever read this, know that you’ve saved my life.
hello, great tutorial, thanks for shearing this, I have some questions, How can I call the image from number, i added to the slideshow some thumbnails and want them to work with the slideshow, like if i click on thumb 5 image 5 loads on stage and the timer continue running, anyone can give me an insight in this one??
Hi,
I am new to flash as2 and i learned a lot from this tutorial
it help me a lot
thanks for this great work.
keep doing great.
Great Work Bryce Howitson !!!
congratulatione.
The source file won’t open in Flash CS3. I get an error saying “unexpected file format”.
Otherwise, a great tutorial!
lol. nerds. its fine for me to work with.
Hello Bryce,
great tutorial, thanks!
By the way, the second photo is the Oropa sanctuary, near Biella (my town) in Italy. What a surprise!
Silvia
Hi,
Great tutorial! I appreciate it being in AS2, thank you. :)
So here’s the thing.
I followed every step and checked each one, but somehow I couldn’t make the pictures appear. The shell_mc works fine, it changes its size according to the picture it ‘supposedly’ loads. But yeah, the tweening works, but weirdly enough, I can’t see the pictures. XD
Any thoughts/opinions on this?
Thanks!
Hej hej,
everything works fine for me. The only thing i had to change was the gs file. Cause when i downloaded it from http://blog.greensock.com/tweenmaxas2 the folder had a different structure. So instead i just downloaded the source file and copied the gs folder into my folder and everything works just perfectly. Thank you!
Thanks, I’m glad you liked the tutorial.
Did you check the paths to your images in the xml file? The image path should be relative to the swf and not to the xml file. The other thing to check is that the images aren’t CMYK Jpegs. Flash doesn’t seem to like those but they’ll display fine in most picture viewers so its a bit hard to catch the problem.
Is there a way to do this without having to type each individual image name in the .xml file? Just point to a folder and pull images from that folder.
Yes, you could have a PHP file that reads all of the contents of a folder and format the XML file for you
Hi!
Awesome Tut. I’m having a problem as I usually use Tweener instead of Tweenlite. I managed to change everything into tweener except the Autoalpha property. How can I translate that into Tweener?
Thanks!
Just a newbee here with Flash MX 2004 Pro. Never could get past Step 7 – “Give the new movieClip an instance name of “background_mc”. Lastly, name the layer “background” and lock it.” Since Step 5 says “Rename “layer 1” to “background”.”, stops with error message “background” already used.
What am I missing?
It would be awesome if we could take this one step further and show how to embed it in HTML. Is there a tutorial here for that? I’ve searched everywhere.
For those of you that want to make a next and previous button to work…here are some quick tips…
When you click on your next button for example, you want to tween the white background, border and mask as well as increment the picture and then display it…right?
Well the code itself is there you just need to manipulate it a bit more…
If you take the code out of the loadListener.onLoadInit function as well the loadListener.onLoadComplete function and put it in your next_btn.onPress function, you should start getting some results…
So when you press the next button:
1) tween the background, border and mask
2) increment the picture
3) display the picture
The only problem I got is that there is a pause between the background tweening and the display of the image…because as you see from onLoadComplete function…it waits to be loaded then it displays the pic…
Anyways I haven’t done it completely, I just played a little with it and got a good start……
Lets hope this helps you guys out…
If you got it to completely work….share it with us!
Thanks
awesome one!, i have a question though , how can i use multiple slide-shows in the same file, say i need to use one in my 1st frame, one in 50th frame ,, like that
Any help will be highly appreciated
Great Tutorial, but please can anyone help, when a use the slideshow onmy web site i put the swf with all the references files in a folder, but when i call to my index the swf doesn’t work, exist some way to put it well and work in a different folder please help me?
I already tried some other scipts but discoverd a lot of problems during testing.
But this one works great and is explained very well !!!
Thank you Bryce!
Tim
it seems I lost i work with this tut but there is no result please help me
this my action script i am working in cs4
import com.greensock.*;
import com.greensock.easing.*;
var xmlPath = “content.xml”;
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList:Array = new Array();
photos_xml.onLoad = function(success) {
if (success) { // ———– load successful
imageList = photos_xml.firstChild.childNodes;
loadImage();
} else {
// ———– problem loading, check path
trace(“Error loading photos_xml”);
}
}
var currentImage:Number = 0;
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(target_mc:MovieClip, httpStatus:Number):Void {
TweenLite.to(shell_mc.background_mc, 0.25, {_width:target_mc._width + 20, _height:target_mc._height + 20, ease:Quad.easeOut});
TweenLite.to(shell_mc.border_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
TweenLite.to(shell_mc.mask_mc, 0.25, {_width:target_mc._width, _height:target_mc._height, ease:Quad.easeOut});
var clipXTarg = Math.round((Stage.width/2)-((target_mc._width+20)/2));
var clipYTarg = Math.round((Stage.height/2)-((target_mc._height+20)/2));
TweenLite.to(shell_mc, 0.25, {_x:clipXTarg, _y:clipYTarg, ease:Quad.easeOut});
}
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
TweenLite.to(target_mc, 0.25, {autoAlpha:100, delay:0.25});
setTimer();
}
function setTimer(){
timer = setInterval(loadImage, 5000);
}
function loadImage(){
var loadURL = imageList[currentImage].attributes.imgurl;
var targetClip = shell_mc.pics_mc.createEmptyMovieClip(“pic”+currentImage,shell_mc.pics_mc.getNextHighestDepth());
targetClip._alpha = 0;
imageLoader.loadClip(loadURL,targetClip);
}
photos_xml.load(xmlPath);
stop();
If your not getting an error but no images show up, there is a good chance that the path to the image file inside the xml document is incorrect. Check to make sure that the xml file paths are relative to the page containing the swf and not to the xml file or the swf itself.
Hello,
what do I need to get this working if i just want one image to show?
Just put one Image in the xml file and remove all the unused nodes.
Although its kind of the with a slide show to have more than one image. Its a lot of overhead if you just need an image to display.
Hi,
It is very helpful, thank u.
I need to add some transition in the images, how could I do that?
Thanks for your help
I’m having trouble replicating something similar to this. I want numerous pictureContainer on the same stage but showing different images but doing the same tween but at different speeds. I have one pictureContainer working but the others are not working. I changed all the instances to a different name and changed it in the as2 but its not playing. I have no errors showing up. I have no clue what I am doing wrong.
Please Help!
Thanks, make me want to try
I’m having a rubbish of a time trying to get this to work on a website. For some reason, the .swf itself works, but when uploaded to the site, it just sits on “loading image” and doesn’t do anything. I copied / pasted the entire folder, then set the .swf in the site…then nothing. Is there anything I can do to fix this issue? May it be a Flash issue, or is it a coding error? Anythink you can tell me would be highly useful.
Thanks.
Hi All very niceTutorial, Player is working very fine at my end.
But i want to add the back next button and also play slideshow button. I Have changed the code in flash but now player stopped working
I am getting error
**Error** Scene=Scene 1, layer=Action Layer, frame=1:Line 11: Syntax error.
currentImage–;
**Error** Scene=Scene 1, layer=Action Layer, frame=1:Line 13: Unexpected ‘}’ encountered
}
Total ActionScript Errors: 2 Reported Errors: 2
my code is:
function setTimer()
{
timer = setInterval(loadImage, 5000);
} // End of the function
function next(){
currentImage++;
loadImage();
}
function previos(){
currentImage–;
loadImage();
}
function removePrevious()
{
if (prevImg != undefined)
{
removeMovieClip (prevImg);
} // end if
if (currentImage < imageList.length – 1)
{
currentImage = currentImage + 1;
}
else
{
currentImage = 0;
} // end else if
} // End of the function
function loadImage()
{
var _loc2 = imageList[currentImage].attributes.thumb;
var _loc1 = shell_mc.pics_mc.createEmptyMovieClip("pic" + currentImage, shell_mc.pics_mc.getNextHighestDepth());
_loc1._alpha = 0;
clearInterval(timer);
imageLoader.loadClip(_loc2, _loc1);
} // End of the function
var xmlPath = "gallery.xml";
var photos_xml = new XML();
photos_xml.ignoreWhite = true;
var imageList = new Array();
photos_xml.onLoad = function (success)
{
if (success)
{
imageList = photos_xml.firstChild.childNodes;
loadImage();
}
else
{
trace ("Error loading photos_xml");
} // end else if
};
var currentImage = 0;
var imageLoader = new MovieClipLoader();
var loadListener = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function (target_mc, httpStatus)
{
gs.TweenLite.to(shell_mc.background_mc, 2.500000E-001, {_width: target_mc._width + 20, _height: target_mc._height + 20, ease: gs.easing.Quad.easeOut});
gs.TweenLite.to(shell_mc.border_mc, 2.500000E-001, {_width: target_mc._width, _height: target_mc._height, ease: gs.easing.Quad.easeOut});
gs.TweenLite.to(shell_mc.mask_mc, 2.500000E-001, {_width: target_mc._width, _height: target_mc._height, ease: gs.easing.Quad.easeOut});
var _loc2 = Math.round(Stage.width / 2 – (target_mc._width + 20) / 2);
var _loc3 = Math.round(Stage.height / 2 – (target_mc._height + 20) / 2);
gs.TweenLite.to(shell_mc, 2.500000E-001, {_x: _loc2, _y: _loc3, ease: gs.easing.Quad.easeOut});
if (currentImage == 0)
{
var _loc4 = imageList.length – 1;
}
else
{
_loc4 = currentImage – 1;
} // end else if
var _loc5 = shell_mc.pics_mc["pic" + _loc4];
gs.TweenLite.to(_loc5, 2.500000E-001, {autoAlpha: 0, onComplete: removePrevious});
};
loadListener.onLoadComplete = function (target_mc)
{
gs.TweenLite.to(target_mc, 2.500000E-001, {autoAlpha: 100, delay: 2.500000E-001});
setTimer();
};
photos_xml.load(xmlPath);
stop ();
nobody alive? i am want to add button back netxt
The clearInterval() tip solved a problem I was having with another similar slideshow code!!!
thanks 1.000.000!
I am trying to resize this to 320×250 and when i do, the images, (which are also 320×250) are resizing inside the document.
It seems as thought they are getting a padding of right 100 + bottom 100. I know this is something that must be within the as file but i cant find it, Im a php developer, pretty new to actionscript.
I need for the images to remain the same size as the document, 320×250. The images will always be at this size. This will be used for ads in a wordpress theme.
Help please!!!
Thanks
I apologize for all of the people who said anything less than complimentary about this tutorial. It’s free, people, be nice. It’s a great tutorial.
Did anybody transform this code to deploy SWF files insted of JPG?
Great slideshow Bryce love it. I was just wondering after reading the comments if anyone got the back and next buttons to work or was ctaminian that last person to attempt it?
Bryce did you ever update your slideshow to integrate the next and back buttons?
Друзья , нужно Ваше мнение , кто знает или сталкивался.
Есть потребность купить колечко с бриллиантом массой более карата, но знаю , что это стоит не мало и мне не по карману.
Но читала , что есть облагороженные бриллианты, которые ничем не отличаются от обычных, но стоят меньше в
два раза.
Кто-нибудь вообще держал такие в руках, они правда красивы ?
nice but useless. As2.0 is dead
Can I make the slide come from the right side out of the stage, then, move into center and stay for 3 mins, then run out to the left side of the stage?