Thursday, December 16, 2010

Create a simple slideshow using AS3: Part 8

Today we will make a 3d spinning slideshow effect.

We've already done something like that in this tutorial, however, in that example we have the picture simply shrinking. Now we will make the effect more 3d-ish:


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 rotateSpeed:int = 10;

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

gallery.rotationY = rotateSpeed;
}

stage.addEventListener(Event.ENTER_FRAME, fadeManager);

function fadeManager(Event):void
{
if (gallery.rotationY != 0)
{
gallery.rotationY +=  rotateSpeed;
}

if (gallery.rotationY == 90)
{
gallery.gotoAndStop(nextframe);
gallery.rotationY = -90;
}

}

Note that it must be possible for 90 to be divided by rotateSpeed.

The code checks if the current rotation is 0. If it isn't - keep rotating the picture. If the rotation equals 90 (the moment we need to change the picture), its rotation is set to -90 and the picture gets changed. After that, it keeps rotating until it reaches 0 and stops.

Thanks 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 4
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 9
Create a simple slideshow using AS3: Part 10

No comments:

Post a Comment