1

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

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

1 回答 1

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();
于 2013-01-03T02:03:34.307 回答