Image Rotator with blur and fadeout
Description: Images are loaded through an XML file and scaled to fit the screen. There is a blur and fade out transition between images.
Author: John Bezanis
Added: March 22nd 2007
Version: Flash 8
Images are loaded in through an XML file, specified by the GET parameter XMLfile. After 200 frames, the next image is loaded and the transition begins, blurring and erasing the previous image. If the applet runs slow, remove the 4 lines used for the blurring. XHTML usage example:
<object data="http://www.bezzmedia.com/swfspot/resources/27-imagerotator.swf?XMLfile=http://www.bezzmedia.com/swfspot/resources/27-imagerotator.xml" type="application/x-shockwave-flash" width="480" height="360"><param name="movie" value="http://www.bezzmedia.com/swfspot/resources/27-imagerotator.swf?XMLfile=http://www.bezzmedia.com/swfspot/resources/27-imagerotator.xml"/></object>
XML file used in the example
Main code for the rotation:
- import flash.filters.BlurFilter;
- stop();
- counter=-1;
- //Check if the GET parameter XMLfile is set, if not use a default file
- if(_root.XMLfile==undefined || _root.XMLfile==""){
- _root.XMLfile="27-imagerotator.xml";
- }
- //Fix the size of the content
- Stage.scaleMode = "noScale";
- //There are 2 movie clips used, and they are rotated
- currentTop=0;
- //Get the percentage loaded of the next image
- function getPercentLoaded(){
- return(100*eval("displayImage"+currentTop).getBytesLoaded()/eval("displayImage"+currentTop).getBytesTotal());
- }
- //Set the current image to the next image
- function nextListImage(){
- currentImage=(currentImage+1)%imageList.length;
- return currentImage;
- }
- //Set the current image to the previous image
- function previousListImage(){
- currentImage=(currentImage-1)%imageList.length;
- if(currentImage<0){currentImage=imageList.length-1;}
- return currentImage;
- }
- //Reset the delay counter, swap the images in depth, and make the top invisible
- function nextImage(){
- counter=200;
- currentTop=(currentTop+1)%2;
- eval("displayImage"+currentTop).swapDepths(eval("displayImage"+((currentTop+1)%2)));
- eval("displayImage"+currentTop)._alpha=0;
- return currentTop;
- }
- //Scale the image to fit the window
- function fitImages(){
- stageRatio=Stage.width/Stage.height;
- docprops=stageRatio+" "+Stage.width+" "+Stage.height;
- topImageRatio=eval("displayImage"+currentTop)._width/eval("displayImage"+currentTop)._height;
- if(isNaN(topImageRatio) || topImageRatio==Infinity){
- }else if(topImageRatio<stageRatio){
- if(eval("displayImage"+currentTop)._height!=Stage.height){
- eval("displayImage"+currentTop)._width*=Stage.height/eval("displayImage"+currentTop)._height;
- eval("displayImage"+currentTop)._height=Stage.height;
- }
- }else{
- if(eval("displayImage"+currentTop)._width!=Stage.width){
- eval("displayImage"+currentTop)._height*=Stage.width/eval("displayImage"+currentTop)._width;
- eval("displayImage"+currentTop)._width=Stage.width;
- }
- }
- eval("displayImage"+currentTop)._x=(550-eval("displayImage"+currentTop)._width)/2;
- eval("displayImage"+currentTop)._y=(400-eval("displayImage"+currentTop)._height)/2;
- }
- var imageList:Array = Array();
- var myXml:XML = new XML();
- myXml.ignoreWhite = true;
- myXml.load(_root.XMLfile);
- //Load the xml file and parse it
- myXml.onLoad = function() {
- currentImage=myXml.childNodes[0].childNodes.length-1;
- for(imageIndex=0;imageIndex<myXml.childNodes[0].childNodes.length;imageIndex++){
- imageList[imageIndex]=myXml.childNodes[0].childNodes[imageIndex].childNodes[0].childNodes[0];
- }
- //reset the delay counter
- counter=200;
- //load an image
- loadMovie(imageList[nextListImage()], eval("displayImage"+nextImage()));
- }
- onEnterFrame=function(){
- counter--;
- //if the xml file has loaded
- if(imageList.length>0 && counter>(-1)){
- //if the delay counter hits 0, load the next image
- if(counter==0){
- loadMovie(imageList[nextListImage()], eval("displayImage"+nextImage()));
- }
- //start the transition after the next image has loaded
- if(eval("displayImage"+currentTop)._alpha<100 && eval("displayImage"+currentTop).getBytesLoaded()==eval("displayImage"+currentTop).getBytesTotal() && eval("displayImage"+currentTop).getBytesLoaded()>0 ){
- //scale the new image
- fitImages();
- //quality of the blur
- quality = 2;
- //The next 4 lines apply a blur to the transition. Remve these lines if the applet runs slow
- var filter:BlurFilter = new BlurFilter(eval("displayImage"+((currentTop+1)%2))._alpha, eval("displayImage"+((currentTop+1)%2))._alpha, quality);
- eval("displayImage"+currentTop).filters=[filter];
- var filter2:BlurFilter = new BlurFilter(eval("displayImage"+currentTop)._alpha, eval("displayImage"+currentTop)._alpha, quality);
- eval("displayImage"+((currentTop+1)%2)).filters=[filter2];
- //fade one in and one out
- eval("displayImage"+currentTop)._alpha+=4;
- eval("displayImage"+((currentTop+1)%2))._alpha-=4;
- //image is still loading
- }else if(eval("displayImage"+currentTop).getBytesLoaded()!=eval("displayImage"+currentTop).getBytesTotal()){
- counter=200;
- }
- }
- }
The source file is available for download
Download Source File
Comments
April 8th 2007 02:04AM - scott
Very interesting ...
i used it... and work very well thanks
i used it... and work very well thanks
May 15th 2007 04:05AM - kostas
was trying to get to work, but keep getting:
Error opening URL "file:///C|/dev/design/dev/taxslayer.com/flash/undefined"
Error opening URL "file:///C|/dev/design/dev/taxslayer.com/flash/undefined"
September 10th 2007 10:09AM - buzz
had to be in same area as default page
September 10th 2007 10:09AM - buzz
Not working properly
Please upload total files in a root
Please upload total files in a root
December 19th 2007 07:12AM - Avijit Brahma
This rotator looks like good solution for my needs (though randomization would be preferable). The blur is a nice touch!
However, I'm having problems resizing the movie. I want to use 765x195 and not 550x400. Changing the Flash stage size and/or the display image script width and height to match in lines 52 and 53 above only allows a thin band of an image to appear at roughly 765 x 50.
I'm testing both PNGs and JPGs at 765x195 dimensions.
Is there some way to allow me to change the size of the movie to suit my needs? Thanks!
However, I'm having problems resizing the movie. I want to use 765x195 and not 550x400. Changing the Flash stage size and/or the display image script width and height to match in lines 52 and 53 above only allows a thin band of an image to appear at roughly 765 x 50.
I'm testing both PNGs and JPGs at 765x195 dimensions.
Is there some way to allow me to change the size of the movie to suit my needs? Thanks!
January 3rd 2008 04:01PM - Cliff
Hmm it seams like the blur effect is eating 50% of the CPU !
I have tried on different maschines. But still a nice flash script. Good work.
January 29th 2008 05:01AM - Jens
great job! thank You.
for those who had problems with resizing: i think i found a bug, and little modification fix it.
line 43:
eval("displayImage"+currentTop)._width*=Stage.height/eval("displayImage"+currentTop)._height;
should probably be:
eval("displayImage"+currentTop)._width*=Stage.width/eval("displayImage"+currentTop)._width;
line 48 vice versa..
it makes sense for me and works =)
for those who had problems with resizing: i think i found a bug, and little modification fix it.
line 43:
eval("displayImage"+currentTop)._width*=Stage.height/eval("displayImage"+currentTop)._height;
should probably be:
eval("displayImage"+currentTop)._width*=Stage.width/eval("displayImage"+currentTop)._width;
line 48 vice versa..
it makes sense for me and works =)
February 9th 2008 04:02PM - tasiek
Cliff,
To shuffle the order add this function:
Array.prototype.shuffle = function() {
var randomNum:Number;
for (i=0; i<this.length; i++) {
if (this[i] == undefined) {
i = i-1;
}
tmp = this[i];
randomNum = Math.floor((Math.random()*(this.length-1))+1);
this[i] = this[randomNum];
this[randomNum] = tmp;
}
};
Then modify the onLoad area like so:
myXml.onLoad = function() {
//CTT Create an array of number range from 0 to length and shuffle it
allNodesArray = new Array();
nodeLength = myXml.childNodes[0].childNodes.length;
for (k=0; k<nodeLength; k++) {
allNodesArray[k] = k;
}
allNodesArray.shuffle();
currentImage = myXml.childNodes[0].childNodes.length-1;
for (imageIndex=0; imageIndex<myXml.childNodes[0].childNodes.length; imageIndex++) {
//CTT use my shuffled array for the index. Replace childNodes[imageIndex] with childNodes[number]
//The childNodes will be loaded in the order of the random array
number = allNodesArray[imageIndex];
imageList[imageIndex] = myXml.childNodes[0].childNodes[number].childNodes[0].childNodes[0];
To shuffle the order add this function:
Array.prototype.shuffle = function() {
var randomNum:Number;
for (i=0; i<this.length; i++) {
if (this[i] == undefined) {
i = i-1;
}
tmp = this[i];
randomNum = Math.floor((Math.random()*(this.length-1))+1);
this[i] = this[randomNum];
this[randomNum] = tmp;
}
};
Then modify the onLoad area like so:
myXml.onLoad = function() {
//CTT Create an array of number range from 0 to length and shuffle it
allNodesArray = new Array();
nodeLength = myXml.childNodes[0].childNodes.length;
for (k=0; k<nodeLength; k++) {
allNodesArray[k] = k;
}
allNodesArray.shuffle();
currentImage = myXml.childNodes[0].childNodes.length-1;
for (imageIndex=0; imageIndex<myXml.childNodes[0].childNodes.length; imageIndex++) {
//CTT use my shuffled array for the index. Replace childNodes[imageIndex] with childNodes[number]
//The childNodes will be loaded in the order of the random array
number = allNodesArray[imageIndex];
imageList[imageIndex] = myXml.childNodes[0].childNodes[number].childNodes[0].childNodes[0];
April 20th 2008 06:04PM - Christian
This is brilliant, thank you. I tried Tasiek's suggestion to fix the resizing issue, but it didn't work. Editing lines 52 and 53 did, though. Change them to the following and the holders should fit the stage, whatever size it is:
eval("displayImage"+currentTop)._x=(Stage.width-eval("displayImage"+currentTop)._width)/2;
eval("displayImage"+currentTop)._y=(Stage.height-eval("displayImage"+currentTop)._height)/2;
eval("displayImage"+currentTop)._x=(Stage.width-eval("displayImage"+currentTop)._width)/2;
eval("displayImage"+currentTop)._y=(Stage.height-eval("displayImage"+currentTop)._height)/2;
May 14th 2008 07:05AM - Dan
any tips as to how to alter this if i want to add some more controls like 1 - 2 - 3 - 4 buttons that would jump to specific images instead of just moving from one image to the next? also wanted to add links to the images but i can't seem to figure out how..
June 25th 2008 11:06PM - jake
i got it to work perfect on my site, thank you so much, and for those who are having issues with scale and size, all you got to do is: download file source, go into flash, rezise the content(background, movie clips) remember there are 2 movieclips that are not visible so make sure you resize those too or it would not work, then go on line 43 and 48 and change them to what TASIEK said on his reply here, and lastly, go to line 52 and 53 and change the width 550 and height 400 to whatever size you want
Good luck :)
Good luck :)
June 28th 2008 02:06AM - Angel
Hi, I was trying above example with local images but it shows "Error opening URL "e:\flash_nilesh\images\26-pic1.jpg". I didn't get wats going wrong with my XML or actionscript. Please give me if there is any solution for this
Thanks
Thanks
July 4th 2008 09:07AM - Nilesh
Hello, this script is grate!!
just what i was looking for.
On thing, is it possible to rotate the images??
I want everything to be like 20º Cc.
Thanks
Gonzalo
just what i was looking for.
On thing, is it possible to rotate the images??
I want everything to be like 20º Cc.
Thanks
Gonzalo
September 2nd 2008 03:09PM - Gonzalo
silly question but I am a total newbie to this flash stuff... how do i change the rate at which the next picture is loaded etc. I can see in the code at the top a bit about counter=200. I am guessing this is what needs to be changed but how/where do i do this?
Brilliant example and just what i was looking for - many thanks.
Brilliant example and just what i was looking for - many thanks.
September 16th 2008 07:09AM - jason
koatas please if you come back here please i willl like to hook up with u ..... am kolade from nigeria...kbaba002@yahoo.com
September 25th 2008 07:09AM - kolade 4m nigeria
Hi Christian, I'm trying to implement the shuffle function but am trouble with where to put each bit of script and how to what to change as I'm new to AS. Would it be possible for you to show the changes in a bit more detail or even the fully edited code. Many thanks
October 1st 2008 05:10AM - Russ
please upload full file link. Plz there is some problem with the script.
October 3rd 2008 03:10AM - Andy
Thanks Done .
October 3rd 2008 03:10AM - Andy
any tips as to how to alter this if i want to add some more controls like 1 - 2 - 3 - 4 buttons that would jump to specific images instead of just moving from one image to the next? also wanted to add links to the images but i can't seem to figure out how..
October 3rd 2008 05:10AM - Andy
Mr. Jake its for you.
You have to load your thumbnails externally and give them respective instance . Now you have do just call the current index of your image you want to call on you function like onRollOver, onRelease
loadMovie(_level0.imageList[0],eval("_level0.displayImage"+_level0.nextImage()));
this worked on myside properly .
And for link use your link root in your function.
Thanks
You have to load your thumbnails externally and give them respective instance . Now you have do just call the current index of your image you want to call on you function like onRollOver, onRelease
loadMovie(_level0.imageList[0],eval("_level0.displayImage"+_level0.nextImage()));
this worked on myside properly .
And for link use your link root in your function.
Thanks
October 3rd 2008 06:10AM - Andy
me sale error "file:///C|/dev/design/dev/taxslayer.com/flash/undefined"
October 21st 2008 01:10PM - juana
For those whow are getting errors like the one below:
file:///C|/dev/design/dev/taxslayer.com/flash/undefined
Suggestion is:
Download the XML file [http://www.bezzmedia.com/swfspot/resources/27-imagerotator.xml] and follow the pattern of specifying URL of your .jpg or other type of picture files using relative or absolute path.
file:///C|/dev/design/dev/taxslayer.com/flash/undefined
Suggestion is:
Download the XML file [http://www.bezzmedia.com/swfspot/resources/27-imagerotator.xml] and follow the pattern of specifying URL of your .jpg or other type of picture files using relative or absolute path.
October 29th 2008 08:10AM - Umar Ali Khan
Thank you very much for that script.
November 19th 2008 02:11AM - saleh
Excellent thanks for this... Is there a page on here to request custom versions of this? For people willing to pay?
December 17th 2008 03:12PM - LeaseDeals
Awesome script. I was wondering if we want to make the images clickable.. how do we do that? I understand we must read the value from the XML file, but then I am unaware of any method that would allow us to add the url directly to the image.
December 24th 2008 04:12PM - Prof
Can anyone explain how to make the transition pass faster?
January 14th 2009 02:01PM - Jason
Good tutorial, would you please tell me in detail how to create dynamick (database ) flash web site, I am very new in this area, I don't have a little knowledge about it, but I am interested to create my own web page in flash.
Example:www.kanalhusene.dk (how to make this kind of web page in flash) :)
Example:www.kanalhusene.dk (how to make this kind of web page in flash) :)
January 28th 2009 10:01PM - Sadiqul Islam
Awesome perfect for our new site, but I have the same question as Jason?? How can I speed up the transition speed??
April 15th 2009 04:04PM - UPS
Has anyone figured out how to add links?
This would be a great function to have.
This would be a great function to have.
May 6th 2009 02:05PM - adding linking
Add a Comment






Or Title, and description.