Guest User

Untitled

a guest
Jan 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*VARIABLES*/
  2.  
  3. // movieclips
  4. var thumbs:Array = new Array(t01_mc,t02_mc,t03_mc,t04_mc,t05_mc);
  5.  
  6. // frame labels
  7. var labels:Array = new Array("img1","img2","img3","img4","img5");
  8.  
  9. // current image
  10. var currentImg:Number = 0;
  11.  
  12. // toggle play state
  13. var isPlaying:Boolean = false;
  14.  
  15. // toggle random function
  16. var isRandom:Boolean = false;
  17.  
  18. /*FUNCTIONS*/
  19.  
  20. //////////////////////////////////////////////////////////////
  21. // init
  22. // Initialize variables
  23. //////////////////////////////////////////////////////////////
  24. function init(){
  25.    
  26.     // set framerate
  27.     stage.frameRate = 60;
  28.    
  29.     // dim/undim buttons
  30.     pauseBtn.alpha = 0.5;
  31.     playBtn.alpha = 1;
  32.     playStartBtn.alpha = 1;
  33.    
  34.     //set properties and add listeners to thumbs
  35.     for(var t=0; t<thumbs.length; t++){
  36.         thumbs[t].buttonMode = true;
  37.         thumbs[t].useHandCursor = true;
  38.         thumbs[t].addEventListener(MouseEvent.CLICK, setNextFrame);
  39.     }
  40.    
  41.     // needed to get hand cursors
  42.     prevBtn.buttonMode = true;
  43.     nextBtn.buttonMode = true;
  44.     playBtn.buttonMode = true;
  45.     playStartBtn.buttonMode = true;
  46.     firstBtn.buttonMode = true;
  47.     lastBtn.buttonMode = true;
  48.     randomBtn.buttonMode = true;
  49.     pauseBtn.buttonMode = true;
  50.    
  51.     // use hand cursors on buttons
  52.     prevBtn.useHandCursor = true;
  53.     nextBtn.useHandCursor = true;
  54.     playBtn.useHandCursor = true;
  55.     playStartBtn.useHandCursor = true;
  56.     firstBtn.useHandCursor = true;
  57.     lastBtn.useHandCursor = true;
  58.     randomBtn.useHandCursor = true;
  59.     pauseBtn.useHandCursor = true;
  60.    
  61. }
  62.  
  63.  
  64.  
  65. //////////////////////////////////////////////////////////////
  66. // setNextFrame
  67. // Determine the next frame to jump to
  68. //////////////////////////////////////////////////////////////
  69. function setNextFrame(evt){
  70.    
  71.     // next button clicked
  72.     if(evt.target == nextBtn){
  73.         // see if currently on last image
  74.         if(currentImg < (thumbs.length - 1)){
  75.             // if not go to next image
  76.             currentImg++;
  77.         }else{
  78.             // if so go to beginning
  79.             currentImg = 0;
  80.         }
  81.     }
  82.    
  83.     // previous button clicked
  84.     if(evt.target == prevBtn){
  85.         //see if on first image
  86.         if(currentImg > 0){
  87.             // if not go to previous image
  88.             currentImg--;
  89.         }else{
  90.             // otherwise to go to last image
  91.             currentImg = thumbs.length -1;
  92.         }
  93.     }
  94.    
  95.     // thumbnail clicked
  96.     for(var i=0; i<thumbs.length; i++){
  97.        
  98.         // check which thumbnail was clicked
  99.         if(evt.target == thumbs[i]){
  100.             // set current image to thumbnail clicked
  101.             currentImg = i;
  102.         }
  103.     }
  104.    
  105.     if(isRandom){
  106.         // set current image to a random number 0-4
  107.         currentImg = (Math.floor(Math.random()*4) + 1);
  108.     }
  109.    
  110.     // reset buttons
  111.     playBtn.alpha = 1;
  112.     playBtn.alpha =1;
  113.    
  114.     // stay on the frame
  115.     isPlaying = false;
  116.    
  117.     // go to next image
  118.     goToNextImage();
  119. }
  120.  
  121.  
  122.  
  123. //////////////////////////////////////////////////////////////
  124. // goToNextImage
  125. // go to the next frame determined by setNextFrame
  126. //////////////////////////////////////////////////////////////
  127. function goToNextImage(){
  128.  
  129.     gotoAndPlay(labels[currentImg]);
  130.    
  131. }
  132.  
  133.  
  134. //////////////////////////////////////////////////////////////
  135. // playHandler
  136. // Determine which play button was pressed and what to do
  137. //////////////////////////////////////////////////////////////
  138. function playHandler(evt){
  139.    
  140.     stage.frameRate = 10;
  141.    
  142.     // if play start button clicked
  143.     if(evt.target == playStartBtn){
  144.         // reference to button
  145.         var currentPlayBtn = evt.target;
  146.        
  147.         // enable pause button
  148.         pauseBtn.alpha = 1;
  149.        
  150.         // set playhead at start
  151.         currentImg = 0;
  152.        
  153.         // if other play button is dimmed
  154.         if(playBtn.alpha != 1){
  155.             // undim it
  156.             playBtn.alpha =1;
  157.         }
  158.     }
  159.    
  160.    
  161.     // if play button clicked
  162.     if(evt.target == playBtn){
  163.         // reference to button
  164.         currentPlayBtn = evt.target;
  165.        
  166.         // enable pause button
  167.         pauseBtn.alpha = 1;
  168.        
  169.         // if other play button is dimmed
  170.         if(playBtn.alpha != 1){
  171.             // undim it
  172.             playBtn.alpha = 1;
  173.         }
  174.     }
  175.    
  176.     // go to next image
  177.     goToNextImage();
  178.    
  179.     // turn continuous play on
  180.     isPlaying = true;
  181.    
  182.     // set button properties
  183.     currentPlayBtn.alpha = .5;
  184.     currentPlayBtn.useHandCursor = false;
  185.    
  186.     // set listeners
  187.     currentPlayBtn.removeEventListener(MouseEvent.CLICK, playHandler);
  188.     addEventListener(Event.ENTER_FRAME, playSlideShow);
  189.    
  190.     pauseBtn.alpha = 1;
  191.     pauseBtn.addEventListener(MouseEvent.CLICK, setPause);
  192. }
  193.  
  194. //////////////////////////////////////////////////////////////
  195. // setPause
  196. // Handle the pause button
  197. //////////////////////////////////////////////////////////////
  198. function setPause(evt){
  199.    
  200.     // if paused clicked
  201.     if(evt.target == pauseBtn){
  202.        
  203.         //turn off playing
  204.         isPlaying = false;
  205.        
  206.         // reset play button properties and listeners
  207.         playBtn.alpha = 1;
  208.         playBtn.addEventListener(MouseEvent.CLICK, playHandler);
  209.        
  210.         // reset play from start button properties and listeners
  211.         playStartBtn.alpha = 1;
  212.         playStartBtn.addEventListener(MouseEvent.CLICK, playHandler);
  213.        
  214.         // reset pause button properties and listeners
  215.         pauseBtn.alpha = .5;
  216.         pauseBtn.removeEventListener(MouseEvent.CLICK, setPause);
  217.     }
  218. }
  219.  
  220. //////////////////////////////////////////////////////////////
  221. // playSlideShow
  222. // Play through all of the images
  223. //////////////////////////////////////////////////////////////
  224. function playSlideShow(evt){
  225.    
  226.     // if slideshow is playing
  227.     if(isPlaying){
  228.        
  229.         // if not at last frame
  230.         if(currentFrame < totalFrames){
  231.             // go to next frame
  232.             nextFrame();
  233.            
  234.         // if at the last frame
  235.         }else{
  236.             // go to beginning
  237.             gotoAndPlay(1);
  238.             //and stay there
  239.             isPlaying = false;
  240.         }
  241.     }
  242.    
  243.     // release the event listener at the end of the slideshow
  244.     if(isPlaying == false){
  245.        
  246.         // set framerate back
  247.         stage.frameRate = 60;
  248.        
  249.         // remove enter frame listener
  250.         removeEventListener(Event.ENTER_FRAME, playSlideShow);
  251.     }
  252. }
  253.  
  254.  
  255. //////////////////////////////////////////////////////////////
  256. // setRandom
  257. // Flip through images randomly (only works with next/previous buttons)
  258. //////////////////////////////////////////////////////////////
  259. function setRandom(evt){
  260.    
  261.     // set variable and dim the icon when clicked
  262.     if (isRandom == true){
  263.         randomBtn.alpha = 1;
  264.         isRandom = false;
  265.     } else if (isRandom == false){
  266.         randomBtn.alpha = 0.5;
  267.         isRandom = true;
  268.     }
  269. }
  270.  
  271.  
  272. //////////////////////////////////////////////////////////////
  273. // gotoFirst
  274. // Jump to beginning of slides
  275. //////////////////////////////////////////////////////////////
  276. function gotoFirst(evt){
  277.     gotoAndPlay(labels[0]);
  278. }
  279.  
  280. //////////////////////////////////////////////////////////////
  281. // gotoLast
  282. // Jump to end of slides
  283. //////////////////////////////////////////////////////////////
  284. function gotoLast(evt){
  285.     gotoAndPlay(labels[labels.length-1]);
  286. }
  287.  
  288.  
  289.  
  290.  
  291. /*FUNCTION CALLS*/
  292. init();
  293.  
  294.  
  295. /*LISTENERS*/
  296.  
  297. prevBtn.addEventListener(MouseEvent.CLICK, setNextFrame);
  298.  
  299. nextBtn.addEventListener(MouseEvent.CLICK, setNextFrame);
  300.  
  301. playBtn.addEventListener(MouseEvent.CLICK, playHandler);
  302. playStartBtn.addEventListener(MouseEvent.CLICK, playHandler);
  303.  
  304. firstBtn.addEventListener(MouseEvent.CLICK, gotoFirst);
  305. lastBtn.addEventListener(MouseEvent.CLICK, gotoLast);
  306.  
  307. randomBtn.addEventListener(MouseEvent.CLICK, setRandom);
Add Comment
Please, Sign In to add comment