Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何在AS3中添加计时器_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 如何在AS3中添加计时器

Actionscript 3 如何在AS3中添加计时器,actionscript-3,flash,Actionscript 3,Flash,我想知道如何在AS3中添加一个ingame定时器,我为敌人的怪物制作了一个健康栏,一旦怪物受到攻击,健康栏就会显示出来。我需要添加一段代码,如果敌人在5秒内没有受到攻击,healthBar.visible=false

我想知道如何在AS3中添加一个ingame定时器,我为敌人的怪物制作了一个健康栏,一旦怪物受到攻击,健康栏就会显示出来。我需要添加一段代码,如果敌人在5秒内没有受到攻击,
healthBar.visible=false


有什么想法吗?

我的建议如下:

假设MouseClick是忍者攻击的英雄。如果使用此代码,则需要创建类或fit类型。我只是写了一些基本代码


你试过什么?你有密码吗?有很多方法。我想支持你们的想法。是的,我有我的代码,一切都很好,一旦忍者被攻击,他就会失去生命。关键是我需要知道如何使Healthbar在5秒后消失。P.S.Healthbar是一部普通电影
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;

stage.addEventListener(MouseEvent.CLICK, onAttacked);

var isAttacked:Boolean;
var timer:Timer = new Timer(100,50);
var alphaCount:Number = 1.0;
timer.addEventListener(TimerEvent.TIMER, onTick);
function onAttacked(e:MouseEvent):void
{
    isAttacked = true;
    timer.start();
}

function onTick(e:TimerEvent):void
{
    alphaCount = 1.0 - ( 2 * timer.currentCount ) / 100;
    if(!isAttacked)
    {
        goFadeStatusBar();
    }
    else
    {
        restoreStatusBar();
        alphaCount = 1.0;
        timer.reset();
        timer.start();
        isAttacked = false;
    }
}

function goFade():void
{
    bar.alpha = alphaCount;
}

function restore():void
{
    bar.alpha = 1;
}