Revision: 54935
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 18, 2012 20:46 by burnandbass
Initial Code
package {
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.EventDispatcher;
public class AutoPilot extends EventDispatcher {
//static const for event dispatching
public static const CHANGE:String = "slideChange"; // dispatched every time slide changes
public static const STOP:String = "slideStop"; // dispatched on stop();
public static const PLAY:String = "slidePlay"; // dispatched on play();
public static const RESUME:String = "slideResume"; // dispatched on resume();
//autoPilot variables
private var _slides:Number;
private var _slideTime:Number;
private var _currentSlide:Number;
private var _timer:Timer;
/*
Author: Chrysto Panayotov ([email protected] for chromeye dev team);
parameters:
@__slides:Number --> number of slides to be cycled;
@_slideTime:Number --> time (in seconds) for the slides to change;
@_autoStart:Boolean ( default true ) --> does the autoStart start automaticly or wait for start();
*/
public function AutoPilot(__slides:Number, __slideTime:Number, _autoStart:Boolean = true) {
_currentSlide = 0;
_slides = __slides;
_slideTime = __slideTime;
_timer = new Timer(_slideTime*1000);
_timer.addEventListener(TimerEvent.TIMER, changeSlide);
if(_autoStart){
play();
}
}
//plays from 0
public function play():void{
_currentSlide = 0;
_timer.start();
dispatchEvent( new Event(AutoPilot.CHANGE) );
dispatchEvent( new Event(AutoPilot.PLAY) );
}
public function stop():void{
_timer.stop();
dispatchEvent( new Event(AutoPilot.STOP) );
}
public function resume():void{
_timer.start();
dispatchEvent( new Event(AutoPilot.RESUME) );
}
//private
private function changeSlide(event:Event = null):void{
_currentSlide = ( ++_currentSlide % _slides );
dispatchEvent( new Event(AutoPilot.CHANGE) );
}
//getters
public function get currentSlide():Number{
return _currentSlide;
}
public function get nextSlide():Number{
return _currentSlide < _slides-1 ? _currentSlide+1 % _slides : 0;
}
public function get previousSlide():Number{
return _currentSlide > 0 ? _currentSlide-1 : _slides-1;
}
}//end
}
Initial URL
cycyle, slideshow, banner
Initial Description
This is lightwave script, made for banners/slideshows. You pass number items, time for slide and autostart. If you have 5 items and pass 2 seconds each, trought 2 seconds interval the numbers will be sldied (1,2,3,4,5,1,2,3,4,5,1,2,3..) and event will be passed. The code is self-explanary, for some real-world examples write me a comment
Initial Title
AutoPilot - cycle items in some seconds
Initial Tags
Initial Language
ActionScript 3