Flash XML Image Slide Show Action Script 3

Hi, every one. I got many queries to write an article regarding How to create Image Slide Shows. Slide shows also referred as web slideshow or web slide shows can be made using java script and Flash. I prefer Flash action script Image Slide Shows over Javascript image slide shows.

Reason for that is with flash we can have variety of flash animations and effects available in action script api. Also we can make our customized flash animated effects. In java script we are very limited in terms of transitions and effects during the image slide show. Also with flash we can have interactive flash side show and banners. Another benefit of using flash image slide show is we can have text added to the animation.

In this flash tutorial we will learn how to create a basic image slide show in flash action script 3, and the type of applications that can be made by using flash image slide shows and few types of flash slideshows.

In future I plan to write a flash component for Image Slide show. I have attached the flash example and source code with the article you can download it at the link at the end of the article.

There are number of flash slide show or presentation creation software available online. They make life complex. In reality it is quite easy to make you own flash animation.

If you are looking for a customize flash animation, image slide show or any flash application you may contact admin@imaginationdev.com

I will be glad to help you out. If you need any advice you may post comments under this article.

There are number of types of flash animation that can be used in creating flash slide shows or animations.

- Flash 3d Slide Show (slideshow)

- Flash Presentation Slide Show (slideshow)

- Flash Banners Slide Show (slideshow)

- Flash Image Galleries Slide Shows (slideshow)

- Flash Text Slide Shows (slideshow)

- Flash Interactive Slide Shows (slideshow)

- Flash Image Slide Shows with Effects

There are 2 basic styles to make flash image slide shows. Namely dynamic image or picture slide show and static image or picture slide show.

Static flash picture slide show usually consists of some images that are internal to the flash and are embedded in the swf files. They have a benefit that there can be various customized animations that we can have in static image slide shows. The problem is they lack in security. There are numbers of flash de-compilers available which can extract the images and other people might use them.

If you want to have more security in terms of image copy rights its always better to use dynamic image or picture slideshow. Dynamic image slideshow are developed by loading external images at run time through XML.

In my flash picture slideshow tutorial I have used the dynamic approach also in flash action script 3 now its really easy to control animation and transition effects through tween classes.

Also by loading external we have a benefit that we can use flash xml image slideshow as a flash random image slideshow.

Here Goes the code for the Loading and Display and Tweening. I have also attached the source code along with all files at the end of the article.

Code:
////////////////////////////////////////////////////////////////////////
// Imports
////////////////////////////////////////////////////////////////////////

import fl.transitions.*;
import fl.transitions.easing.*;

////////////////////////////////////////////////////////////////////////
// Variables Initiation and Declaration
////////////////////////////////////////////////////////////////////////

var pic_prev_mc:MovieClip=new MovieClip();
var pic_mc:MovieClip=new MovieClip();
var picInitial_mc:MovieClip=new MovieClip();
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML;
var thumbLoader:Loader;
var index:int=0;
var picArray:Array=new Array();
var timer :Timer=new Timer(1000,4);
var curr:int=1;
var totalPictures:int;
var flag:int=0;
var bitmap:DisplayObject;
var effect:Object=Photo;

////////////////////////////////////////////////////////////////////////
// Function XMl Loading
////////////////////////////////////////////////////////////////////////
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
var httpHeader : URLRequestHeader = new URLRequestHeader(”pragma”,”no-cache”);
var path:String=”Banner.xml”;
xmlLoader.load(new URLRequest(path));

function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
stage.scaleMode = StageScaleMode.EXACT_FIT;
stage.stageWidth= xmlData.Width;
stage.stageHeight=xmlData.Height;
getValues(xmlData);

}// end of Load XML
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,funcError);
function funcError(event:IOErrorEvent){
trace(”Error occured in XML Loading”);
}
function getValues(input:XML) {
var xmlCategoryList:XMLList = input.children();
totalPictures=input.children().length();
var item:XML;
for each (item in xmlCategoryList) {

loadThumbs();
}
}
////////////////////////////////////////////////////////////////////////
// Function loadThumbs
////////////////////////////////////////////////////////////////////////
function loadThumbs():void {
thumbLoader = new Loader();
thumbLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadThumbProgress);
thumbLoader.contentLoaderInfo.addEventListener(Event.INIT, thumbLoaded);
thumbLoader.load(new URLRequest(String(xmlData.path[index])));//access the thumbnails

function loadThumbProgress(e:ProgressEvent):void {
}
////////////////////////////////////////////////////////////////////////
// Function thumbloaded
////////////////////////////////////////////////////////////////////////
function thumbLoaded(e:Event):void {
for(var i:int=0;i<totalPictures;i++){;
picArray[i]=xmlData.path[i];

}
addChild(picInitial_mc);
picInitial_mc.addChild(thumbLoader.content);
bitmap=thumbLoader.content;
}
function xmlLoadFail(event:IOErrorEvent):void {
trace(”error loading the XML”);
}
}
////////////////////////////////////////////////////////////////////////
// Function Next Pic Loading
////////////////////////////////////////////////////////////////////////

function nextPicLoad(string:String) {
thumbLoader = new Loader();
thumbLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadThumbProgress);
thumbLoader.contentLoaderInfo.addEventListener(Event.INIT, thumbLoaded);
thumbLoader.load(new URLRequest(String(string)));

function thumbLoaded(e:Event):void {
stage.addChild(thumbLoader.content);
addChild(pic_mc);
addChild(thumbLoader.content);
pic_mc.addChild(thumbLoader.content);
bitmap=thumbLoader.content;
//Blinds, Fade, Iris, Photo, PixelDissolve, Rotate, Squeeze, Wipe, or Zoom.
TransitionManager.start(pic_mc, {type:Fade, direction:Transition.IN, duration:1, easing:Regular.easeInOut});
TransitionManager.start(pic_mc, {type:Wipe, direction:Transition.IN, duration:1, easing:Regular.easeIn});

}
function loadThumbProgress(e:ProgressEvent):void {
}

}

////////////////////////////////////////////////////////////////////////
// Function Pic Display
////////////////////////////////////////////////////////////////////////

function picDisplay() {
timer.start();
timer.addEventListener(TimerEvent.TIMER_COMPLETE,funcTimer);
function funcTimer(event:TimerEvent) {
for(var k:int=0;k<pic_mc.numChildren;k++){
pic_mc.removeChildAt(k);

}
if (flag==0) {
flag=1;
removeChild(picInitial_mc);
} else {
removeChild(pic_mc);
}
addChild(bitmap)
nextPicLoad(picArray[curr]);
curr++;

if (curr==totalPictures) {
curr=0;
}
timer.reset();
timer.start();
}
}
picDisplay();
stop();

I have attached the code for free flash image slideshow. you are free to use and modify the code the way you like.

Kindly Let me know about your remarks if this article is being helpful in solving your problem.

Download Sample Project : Image Slide Show Source Code

A running sample can be viewed at the following link

http://actionscript-blog.imaginationdev.com/samples/banner-slideshow/Banner.swf

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

GOOD ARTICLE. But the link you given for Download project and sample project does not work. Kindly make a note of it.

[Reply]

admin Reply:

It is working man

[Reply]

hi . Geetha .. thanx i will update the link today .

[Reply]

Link is fixed now :)

[Reply]

Thanks for this, looking for a quick solution. I get this error message just after the first picture

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-376()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/flash.utils:Timer::tick()

What does this mean?

[Reply]

HI this is probably caused when you are trying to remove a child that from a movie clip and that is not the child of that ovie clip or not yet has been added or it was already removed

What code are you using . have you changed the code that you have downloaded

Thank you

[Reply]

No I haven’t touched the code.

[Reply]

Dear Sir

But the link you given for Download project and sample project is not running after downloading the same. It means source file is not working + swf also

Kindly me back
Thank you

[Reply]

Hi Roy and Anand Sorry about the in-convenience. I will have a look at the code today
and will update that and upload that keep in touch and Kindly subscribe to the Blog so you are notified all the time i update that

Thanks

[Reply]

I think the solution to this is very easy (at least for me!). I fixed mine by just rearranging the paths in the XML file. You may have not noticed, but they’re not in order. So you can fix this by putting

images/1.jpg
images/2.jpg
images/3.jpg

And with making sure that all the correct files are there (1.jpg, 2.jpg, 3.jpg etc)

There was no problem with the code whatsoever.

Thanks again

[Reply]

I am re witting the existing code . Making some changes that will help to improve the efficiency of the code

Thank you for the patience

Bilal

[Reply]

Yah Thank you Roy. I guess i updated the other version of XML . :) Any ways Thanks a lot for pointing this out. Actually now a days i m so much busy that it creates a few days gap. Any ways i m working on a flash image gallery stuff probably would update another article in a month. The gallery is a total customizable AS3 solution for image galleries

Thank you for all your support . I really appreciate .. I guess now i dont have to update the code for time being. But in a week i will update a new code .. or may be i focus now on new article. What you guys suggest.

Hope fully

Thanx.

[Reply]

nice one.
how could it be modified to rotate random images out of different folders using xml?

[Reply]

What do you mean by rotation of images ?

[Reply]

i mean the slideshow… how could i adjust this code to pick out the images from the XML list randomly and not by order as it is now?

[Reply]

besides the randomness isue… i have another tricky question. i’m playing around with it but can’t find the right way to do this: i have 3 different folders filled with images. i want to randomly pick images from those 3 folders, but have a variable different image pausing time for each folder. meaning, all images in /folder1/ will have a slideshow session of 1sec, images in /folder2/ will stay on for 4sec, and so on.

[Reply]

Is it possible to resize the swf without resizing the images? so when I want to set the width and height to 200 x 200 the images shows from left top to the max height and the max witdth?
The next time I want to use it in 300 x 100 pixels.. etc.. when I do this now the image is scaling and when I change the scalemode into no_scale, the image is running of the edge… I hope you will understand me (not so good in english :-) )

[Reply]

stage.align = StageAlign.TOP_LEFT;

is the solution :) i didn’t know this method

[Reply]

HI, :) bert man where you asking or sujjesting the solution ?
to control height and width you can do that through the Html where you embed flash
swf?

Or let me know whats the exact questin that you want to know . i m a little confused here :)

[Reply]

Hi,

Great article I am very pleased with the outcome!

An error is cropping up when I test the movie and select simulate download. The error is as follows;

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-385()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()

How can I fix this? I am stuck

[Reply]

To get random image you need to generate a random number every time in the timer

Use Math.random function and than access that random location in the array and display that image …

So the images will be loaded sequentially but after taht they will appear in random fassion ..

I hope that answers your question Bert

Thanks.

[Reply]

Hi, Thomas what you need to do is open XML file and arrange the image names in sequence and in the image folder name the images in sequence

like image 1.jpg , 2.jpg , … and so on .. Sequence should not break .

Than if same problem comes let me know ..

I will soon upload a latest version of slide show hope fully as soon as i get time

Regards

Billy

[Reply]

HI Billy,

Thanks for your prompt reply,

I removed most of images from the XML file and only 3 images are being displayed.
When I click on Test Movie it works fine but when I click on TEST MOVIE > SIMULATE DOWNLOAD the same error as previously is shown.

The is always happening on the second image caused by the Timer event.

I tried to fix it….. but I got no where close.

Once again thanks for sharing this sideshow.

Regards,
Thomas

[Reply]

what you need is name the 3 images as 1.jpg,2.jpg and 3.jpg and also in xml file name them in sequence

Thanks

[Reply]

http://www.hulu.com/ -

i want a flash slideshow/banner same like the above link … can you help me out …
where i can get the same type of banner.

[Reply]

Hello, I am getting ready to pull my hair out when I found your site. Here’s my problem:

I need a VERY simple xml slideshow that the user can stop and play using buttons. I will only have 5 images on the slideshow. I need the user to be able to click any of the slides and go to the URL of the image listed within the xml files. So, basically I will have small thumbnails on the slideshow and when an image is clicked, it will go to a URL with a bigger image size. I need the show to be on a timer so that the user can click play or pause and have the show do just that.

I am barely getting the xml files loaded and I have no clue as to how to write the function to start the show when the user clicks play. I am using AS3

Thanks for any advice you may have.

[Reply]

I want a code of how to change width & height of external image .

which we call in our flash file in movie clip

[Reply]

hi Trish Sanchez

I m still waiting for your email response .. you already have my email address

Thank you

[Reply]

HI Sona :

Once you have loaded the Image in flash … in onLoadComplete event change or scale the height and width of the image

Thanks

Bill

[Reply]

Hi,

This is great, I am new in AS and this gives me a lot of food for toughts!

Quick question,

What would be the way to add a text that will run on top of the slide show.

(On the main stage, not attached to any pictures).

Thank you in advance.

Nolwen

[Reply]

Create Dynamic text objects and Tween them .. using animation classes available in AS3.

Thank you

[Reply]

How can I make the images link to an url?

[Reply]

apply on click event handler to dynamic objects that are being created when loading the image and … in that event handler Open up that link that you want.

Thanks

[Reply]

How come it doesn’t work when I embed it in HTML? Works fine when I preview it, works fine when I look at the swf itself on the server, but it won’t load within the website.

[Reply]

hi tried to download ur link Download Sample Project : Image Slide Show Source Code
for the source code n i tried to open the banner flash document file in Macromedia flash professional 8 , but its saying unexpected file format. so ur source code wont work or open in flash 8?
please let me know about this.

[Reply]

Hi Auddi … you need to Update the path in the fla file according to the html.

[Reply]

Hi Renji … you need to use Adobe flash cs3 .. in order to run the code

[Reply]

Thanks! Just what I needed.

[Reply]

hey ADMIN,

Could you be a little more specific about how to make this code generate a random image in the set. I am kind of lost in the code as to where to make the math.random addition.

[Reply]

alot of unused code in there, and it looks to me that you addChild() some extra times.

Good to share :)

[Reply]

hey, I’ve been looking for something exactly like this. I’m getting hte same errors when I try to use it as well:

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-371()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()

and I’ve gone in and reorderd the XML file and checked my images as well. This is pretty close to what i’m looking for, but I want something that works exactly like the banner found here:

http://www.brandonpeterson.com/wordpress/

I”m not sure how it’s done. The image holds and pans then transitions to a new image. And the fact that there are so many images leads me to believe it’s being dynamically called from an XML, but the fact that the images hold on specific areas of the image leads me to think that maybe then went in and keyed the tweens of all those images (and it’s a LOT of them). Any advice would be great.

[Reply]

admin Reply:

Hi try using this enhanced code

http://actionscript-blog.imaginationdev.com/24/xml-flash-image-slide-show-enhanced/

Thanks

[Reply]

actually, an addendum:

it appears his slide holds then pans down, then transitions and repeats. This should totally be doable with an .swf calling an XML.

hralp please!

and how do I put this into another flash file? I mean I know I can embed this into an html or use Dreamweaver, but say I have some other flash functionality going on, but want this to be done in a specific window in flash while my other functionality is going on? I know, a lot to ask.

[Reply]

Hi , I have updated the code for you guys you can view this latest post :

http://actionscript-blog.imaginationdev.com/24/xml-flash-image-slide-show-enhanced/

Thanks every one

[Reply]

hi, i want to build up a flash image slide show. calling images dynamically from a folder.
i want an option to upload new images directly from that folder itself without opening flash. can you please help me to solve my problem.

Thanks In Advance………

[Reply]

hi, you have given me a valuable information…..in your sample i need a buttons with serials 1 2 3 4 5 6 7 8 9….(no.of images included) while clicking the particular no. the respective should display…can u give me a solution..plz…..thanks in advance..

[Reply]

This is the link I used to do the exact thing you are looking for, ARYAN. It is a random slideshow that calls images from a folder. All you have to do to add new images is upload them to the folder and add them to the XML file…

http://www.webzo.org/tutorials/flash/xml-random-image-slideshow.php

My problem is that I want to have a little more control over the “randomization”. Right now it is so random that I often get the same image repeating two or three times before it goes to the next. Does anyone know a way I can have all of the images play BEFORE it starts going random?? Any help would be appreciated as I need this in a hurry! Thanks!!!

[Reply]

This is the link I used to do the exact thing you are looking for, ARYAN. It is a random slideshow that calls images from a folder. All you have to do to add new images is upload them to the folder and add them to the XML file…

http://www.webzo.org/tutorials/flash/xml-random-image-slideshow.php

My problem is that I want to have a little more control over the “randomization”. Right now it is so random that I often get the same image repeating two or three times before it goes to the next. Does anyone know a way I can have all of the images play BEFORE it starts going random?? Any help would be appreciated as I need this in a hurry! Thanks!!!

[Reply]

admin Reply:

Hi every one try using this enhanced code

Hi , I have updated the code for you guys you can view this latest post :

http://actionscript-blog.imaginationdev.com/24/xml-flash-image-slide-show-enhanced/

Thanks every one

[Reply]

Thanks so much for this tutorial. It greatly improved my knowledge in Flash especially in CS3. I would like to know if there was a way to resize the slideshow so that the images weren’t covering the stage completely but only a small portion? I hope this makes sense. Thanks a lot.

[Reply]

Hi Aryan .. At the moment flash cannt access a disc. What you have to do is use php or any other server side language to generate an XML with information of all files and feed that into flash.

[Reply]

This is really an awesome drunken crazy code.

A lot of function in function
I’ve checked this in the debugger, at the start the first picture was loaded 10 times, like the length of the childnodes in the xml:

for each (item in xmlCategoryList) {

loadThumbs();
}

Maybe take a look in some books and reduce the code at half of the length…

[Reply]

admin Reply:

I understand what you are saying. this code was just for Beginners. Have a look at the update code for flash slide show.

http://actionscript-blog.imaginationdev.com/24/xml-flash-image-slide-show-enhanced/

[Reply]

Hi

Your code works great! How would i be able to start the slideshow from the beginning again once it reaches the last image?

Please help…

[Reply]

Download project and sample project does not work.I have rearranged jpg images serialy still it stops at image 2.
could you please advise and guide me. I am new to flash and I use flash 8. with as 2.0
thanks

[Reply]

admin Reply:

I understand what you are saying. this code was just for Beginners. Have a look at the update code for flash slide show.

http://actionscript-blog.imaginationdev.com/24/xml-flash-image-slide-show-enhanced/

[Reply]

[Reply]

Very nice tutorial. Just what I was looking for.

I need some help. I mean I want to built a homepage on top of this slide show. Like, the logo and navigation in the front and the slideshow playing at the background. When I tried to do that, the Logo and Navigation fades with the images. How can I retain the Logo and Navigation but have the slideshow play at the background?

I’m not an expert in AS 3.0. So, any help would be greatly appreciated.

Thanks

[Reply]

Leave a comment

(required)

(required)