2013-01-02 67 views
1

我想在幾秒鐘後查看每張圖片。 功能顯示正在程序中滾動。 請添加必要的代碼。 我無法理解actionscript的定時器功能。查看圖片timer actionscript3,0(FLASH BUILDER)

  function display(q:int):void{ 
      if(q ==0) 
      { 
       ue.visible= true; 
       migi.visible= false; 
       shita.visible= false; 
       hidari.visible= false; 
      } 
      else if(q ==1) 
      { 

       ue.visible= false; 
       migi.visible= true; 
       shita.visible= false; 
       hidari.visible= false; 
      } 
      else if(q ==2) 
      { 
       ue.visible= false; 
       migi.visible= false; 
       shita.visible= true; 
       hidari.visible= false; 
      } 
      else 
      { 
       ue.visible= false; 
       migi.visible= false; 
       shita.visible= false; 
       hidari.visible= true; 
      } 
       } 

回答

0

請嘗試以下操作。我試圖包括評論來解釋我在做什麼:

import flash.utils.Timer; 
import flash.events.TimerEvent; 

// Put all the clips in an array to manage 
var pictures:Array = [this.ue, this.migi, this.shita, this.hidari]; 

// Store the current image index 
var currentPicture = 0; 

// Delay in milliseconds to wait between each image 
var delay = 1000; 

// We can reuse the same timer instance throughout cycle 
var timer:Timer = new Timer(this.delay, 1); 
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler); 

// Hide all the pictures in the array 
function hidePictures():void 
{ 
    for (var i:int = 0; i < this.pictures.length; i ++) 
    { 
     MovieClip(this.pictures[i]).visible = false; 
    } 
} 

function showPicture():void 
{ 
    // Show the current image 
    MovieClip(this.pictures[this.currentPicture]).visible = true; 

    // Now start the pause on the current image 
    timer.start(); 
} 

function timerCompleteHandler(event:TimerEvent):void 
{ 
    // Hide the old image 
    MovieClip(this.pictures[this.currentPicture]).visible = false; 

    // Increment current picture index unless we're at the end in which case loop 
    this.currentPicture = (this.currentPicture < this.pictures.length - 1) 
     ? this.currentPicture + 1 : 0; 

    // Show the next picture 
    showPicture(); 
} 

hidePictures(); 
showPicture();