Sunday, December 12, 2010

Create a simple slideshow using AS3: Part 4

Today we'll make another slideshow effect.

This time the photo turns:


What basically happens, is that when the timer loops, the picture starts shrinking. Once it's scaleX is 0, it starts growing to its initial sizes, but with another photo on it.

Here's the code:

import flash.utils.Timer;

gallery.stop();

var changeTimer:Timer = new Timer(2000);
changeTimer.addEventListener(TimerEvent.TIMER, updateSlideshow);
changeTimer.start();

var nextframe:int;
var goScaleX:int = 1;

function updateSlideshow(TimerEvent):void
{
if (gallery.currentFrame < gallery.totalFrames)
{
nextframe = gallery.currentFrame + 1;
}
else if (gallery.currentFrame == gallery.totalFrames)
{
nextframe = 1;
}

goScaleX = 0;
}

stage.addEventListener(Event.ENTER_FRAME, fadeManager);

function fadeManager(Event):void
{
if (gallery.scaleX > goScaleX)
{
gallery.scaleX -=  0.05;
}
else if (gallery.scaleX < goScaleX)
{
gallery.scaleX +=  0.05;
}
if (gallery.scaleX <= 0)
{
gallery.gotoAndStop(nextframe);
goScaleX = 1;
}
}
Thank you for reading!

Related:

Create a simple slideshow using AS3: Part 1
Create a simple slideshow using AS3: Part 2
Create a simple slideshow using AS3: Part 3
Create a simple slideshow using AS3: Part 5
Create a simple slideshow using AS3: Part 6
Create a simple slideshow using AS3: Part 7
Create a simple slideshow using AS3: Part 8
Create a simple slideshow using AS3: Part 9
Create a simple slideshow using AS3: Part 10

No comments:

Post a Comment