This time I will show you how you can add an auto slideshow feature to the Slideshow component, using the Timer class.

It’s pretty easy to do this, if you know how to use the Timer class, so I will just show you the code without explaining each step, but if you have any specific question, fell free to ask. Also make sure to read the documentation for the Slideshow component.

  1. import com.flashotaku.slideshow.events.SlideshowEvent;
  2. import flash.events.MouseEvent;
  3. import flash.utils.Timer;
  4. import flash.events.TimerEvent;  
  5.  
  6. var myTimer:Timer = new Timer(1500);  
  7.  
  8. start.addEventListener(MouseEvent.CLICK, startHandler);
  9. pause.addEventListener(MouseEvent.CLICK, pauseHandler);
  10. prev.addEventListener(MouseEvent.CLICK, prevHandler);
  11. next.addEventListener(MouseEvent.CLICK, nextHandler);  
  12.  
  13. function startHandler(event:MouseEvent){
  14.         if(!myTimer.hasEventListener(TimerEvent.TIMER)){
  15.                 myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
  16.                 myTimer.start();
  17.         }
  18. }  
  19.  
  20. function timerHandler(event:TimerEvent){
  21.         myTimer.reset();
  22.         myTimer.removeEventListener(TimerEvent.TIMER, timerHandler);
  23.         mySlideshow.nextImage();
  24.         if(!mySlideshow.hasEventListener(SlideshowEvent.TRANSITION_COMPLETE)){
  25.                 mySlideshow.addEventListener(SlideshowEvent.TRANSITION_COMPLETE, completeHandler);
  26.         }
  27. }  
  28.  
  29. function completeHandler(event:SlideshowEvent){
  30.         myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
  31.         myTimer.start();
  32. }  
  33.  
  34. function pauseHandler(event:MouseEvent){
  35.         stopTimer();
  36. }  
  37.  
  38. function prevHandler(event:MouseEvent){
  39.         stopTimer();
  40.         mySlideshow.prevImage();
  41. }  
  42.  
  43. function nextHandler(event:MouseEvent){
  44.         stopTimer();
  45.         mySlideshow.nextImage();
  46. }  
  47.  
  48. function stopTimer(){
  49.         if(myTimer.hasEventListener(TimerEvent.TIMER)){
  50.                 myTimer.reset();
  51.                 myTimer.removeEventListener(TimerEvent.TIMER, timerHandler);
  52.         }
  53.         if(mySlideshow.hasEventListener(SlideshowEvent.TRANSITION_COMPLETE)){
  54.                 myTimer.reset();
  55.                 mySlideshow.removeEventListener(SlideshowEvent.TRANSITION_COMPLETE, completeHandler);
  56.         }
  57. }

The result is this:

Download sample files

Support

As of 11 March 2009, support is no longer provided for the free components. If you need support, please purchase the commercial version of the components.