Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*VARIABLES*/
- // movieclips
- var thumbs:Array = new Array(t01_mc,t02_mc,t03_mc,t04_mc,t05_mc);
- // frame labels
- var labels:Array = new Array("img1","img2","img3","img4","img5");
- // current image
- var currentImg:Number = 0;
- // toggle play state
- var isPlaying:Boolean = false;
- // toggle random function
- var isRandom:Boolean = false;
- /*FUNCTIONS*/
- //////////////////////////////////////////////////////////////
- // init
- // Initialize variables
- //////////////////////////////////////////////////////////////
- function init(){
- // set framerate
- stage.frameRate = 60;
- // dim/undim buttons
- pauseBtn.alpha = 0.5;
- playBtn.alpha = 1;
- playStartBtn.alpha = 1;
- //set properties and add listeners to thumbs
- for(var t=0; t<thumbs.length; t++){
- thumbs[t].buttonMode = true;
- thumbs[t].useHandCursor = true;
- thumbs[t].addEventListener(MouseEvent.CLICK, setNextFrame);
- }
- // needed to get hand cursors
- prevBtn.buttonMode = true;
- nextBtn.buttonMode = true;
- playBtn.buttonMode = true;
- playStartBtn.buttonMode = true;
- firstBtn.buttonMode = true;
- lastBtn.buttonMode = true;
- randomBtn.buttonMode = true;
- pauseBtn.buttonMode = true;
- // use hand cursors on buttons
- prevBtn.useHandCursor = true;
- nextBtn.useHandCursor = true;
- playBtn.useHandCursor = true;
- playStartBtn.useHandCursor = true;
- firstBtn.useHandCursor = true;
- lastBtn.useHandCursor = true;
- randomBtn.useHandCursor = true;
- pauseBtn.useHandCursor = true;
- }
- //////////////////////////////////////////////////////////////
- // setNextFrame
- // Determine the next frame to jump to
- //////////////////////////////////////////////////////////////
- function setNextFrame(evt){
- // next button clicked
- if(evt.target == nextBtn){
- // see if currently on last image
- if(currentImg < (thumbs.length - 1)){
- // if not go to next image
- currentImg++;
- }else{
- // if so go to beginning
- currentImg = 0;
- }
- }
- // previous button clicked
- if(evt.target == prevBtn){
- //see if on first image
- if(currentImg > 0){
- // if not go to previous image
- currentImg--;
- }else{
- // otherwise to go to last image
- currentImg = thumbs.length -1;
- }
- }
- // thumbnail clicked
- for(var i=0; i<thumbs.length; i++){
- // check which thumbnail was clicked
- if(evt.target == thumbs[i]){
- // set current image to thumbnail clicked
- currentImg = i;
- }
- }
- if(isRandom){
- // set current image to a random number 0-4
- currentImg = (Math.floor(Math.random()*4) + 1);
- }
- // reset buttons
- playBtn.alpha = 1;
- playBtn.alpha =1;
- // stay on the frame
- isPlaying = false;
- // go to next image
- goToNextImage();
- }
- //////////////////////////////////////////////////////////////
- // goToNextImage
- // go to the next frame determined by setNextFrame
- //////////////////////////////////////////////////////////////
- function goToNextImage(){
- gotoAndPlay(labels[currentImg]);
- }
- //////////////////////////////////////////////////////////////
- // playHandler
- // Determine which play button was pressed and what to do
- //////////////////////////////////////////////////////////////
- function playHandler(evt){
- stage.frameRate = 10;
- // if play start button clicked
- if(evt.target == playStartBtn){
- // reference to button
- var currentPlayBtn = evt.target;
- // enable pause button
- pauseBtn.alpha = 1;
- // set playhead at start
- currentImg = 0;
- // if other play button is dimmed
- if(playBtn.alpha != 1){
- // undim it
- playBtn.alpha =1;
- }
- }
- // if play button clicked
- if(evt.target == playBtn){
- // reference to button
- currentPlayBtn = evt.target;
- // enable pause button
- pauseBtn.alpha = 1;
- // if other play button is dimmed
- if(playBtn.alpha != 1){
- // undim it
- playBtn.alpha = 1;
- }
- }
- // go to next image
- goToNextImage();
- // turn continuous play on
- isPlaying = true;
- // set button properties
- currentPlayBtn.alpha = .5;
- currentPlayBtn.useHandCursor = false;
- // set listeners
- currentPlayBtn.removeEventListener(MouseEvent.CLICK, playHandler);
- addEventListener(Event.ENTER_FRAME, playSlideShow);
- pauseBtn.alpha = 1;
- pauseBtn.addEventListener(MouseEvent.CLICK, setPause);
- }
- //////////////////////////////////////////////////////////////
- // setPause
- // Handle the pause button
- //////////////////////////////////////////////////////////////
- function setPause(evt){
- // if paused clicked
- if(evt.target == pauseBtn){
- //turn off playing
- isPlaying = false;
- // reset play button properties and listeners
- playBtn.alpha = 1;
- playBtn.addEventListener(MouseEvent.CLICK, playHandler);
- // reset play from start button properties and listeners
- playStartBtn.alpha = 1;
- playStartBtn.addEventListener(MouseEvent.CLICK, playHandler);
- // reset pause button properties and listeners
- pauseBtn.alpha = .5;
- pauseBtn.removeEventListener(MouseEvent.CLICK, setPause);
- }
- }
- //////////////////////////////////////////////////////////////
- // playSlideShow
- // Play through all of the images
- //////////////////////////////////////////////////////////////
- function playSlideShow(evt){
- // if slideshow is playing
- if(isPlaying){
- // if not at last frame
- if(currentFrame < totalFrames){
- // go to next frame
- nextFrame();
- // if at the last frame
- }else{
- // go to beginning
- gotoAndPlay(1);
- //and stay there
- isPlaying = false;
- }
- }
- // release the event listener at the end of the slideshow
- if(isPlaying == false){
- // set framerate back
- stage.frameRate = 60;
- // remove enter frame listener
- removeEventListener(Event.ENTER_FRAME, playSlideShow);
- }
- }
- //////////////////////////////////////////////////////////////
- // setRandom
- // Flip through images randomly (only works with next/previous buttons)
- //////////////////////////////////////////////////////////////
- function setRandom(evt){
- // set variable and dim the icon when clicked
- if (isRandom == true){
- randomBtn.alpha = 1;
- isRandom = false;
- } else if (isRandom == false){
- randomBtn.alpha = 0.5;
- isRandom = true;
- }
- }
- //////////////////////////////////////////////////////////////
- // gotoFirst
- // Jump to beginning of slides
- //////////////////////////////////////////////////////////////
- function gotoFirst(evt){
- gotoAndPlay(labels[0]);
- }
- //////////////////////////////////////////////////////////////
- // gotoLast
- // Jump to end of slides
- //////////////////////////////////////////////////////////////
- function gotoLast(evt){
- gotoAndPlay(labels[labels.length-1]);
- }
- /*FUNCTION CALLS*/
- init();
- /*LISTENERS*/
- prevBtn.addEventListener(MouseEvent.CLICK, setNextFrame);
- nextBtn.addEventListener(MouseEvent.CLICK, setNextFrame);
- playBtn.addEventListener(MouseEvent.CLICK, playHandler);
- playStartBtn.addEventListener(MouseEvent.CLICK, playHandler);
- firstBtn.addEventListener(MouseEvent.CLICK, gotoFirst);
- lastBtn.addEventListener(MouseEvent.CLICK, gotoLast);
- randomBtn.addEventListener(MouseEvent.CLICK, setRandom);
Add Comment
Please, Sign In to add comment