查看图片计时器actionscript3,0(FLASH BUILDER)

时间:2013-01-02 19:42:44

标签: actionscript time timer

我想在几秒钟后查看每张照片。 功能显示在程序中滚动。 请添加必要的代码。 我无法理解actionscript的计时器功能。

            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;
            }
                }

1 个答案:

答案 0 :(得分: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();