【问题标题】:Triggering timer as movie clips enter the stage and stopping them when movie clips leave the stage [as3]当影片剪辑进入舞台时触发计时器并在影片剪辑离开舞台时停止它们[as3]
【发布时间】:2013-10-24 09:05:30
【问题描述】:

任何人都可以告诉我如何编写代码来制作当影片剪辑进入舞台时开始的计时器以及当影片剪辑移出舞台时停止的计时器。

我已将某些影片剪辑放置在舞台外,并让它们在舞台上从右向左移动(当然,在 x 轴上,一次 3 个像素)。随着每个影片剪辑进入舞台,应触发相关的计时器。当定时器被触发时,它将每隔两秒开始播放一个特定的音频剪辑。并且当影片剪辑移出舞台时,计时器应该停止,因此 mp3 音频也将停止。请推荐一些 NON-OOP 方法。它只是我需要的“触发”和“停止”部分。

stage.addEventListener(Event.ENTER_FRAME, loop)
function loop(e:Event){
if(e1.x <= -250){e1.x = 1250;}
if(e2.x <= -350){e2.x = 1325;}
if(e3.x <= -450){e3.x = 1400;}
if(e4.x <= -550){e4.x = 1475;}
if(e5.x <= -650){e5.x = 1550;}
if(e6.x <= -750){e6.x = 1625;}

e1.x -= 3;  
e2.x -= 3;
e3.x -= 3;  
e4.x -= 3;
e5.x -= 3;  
e6.x -= 3;
}

【问题讨论】:

    标签: actionscript-3


    【解决方案1】:

    你几乎已经做到了:

    stage.addEventListener(Event.ENTER_FRAME, loop)
    function loop(e:Event){
    
    if(e1.x <= -250)
    {
        e1.x = 1250;
        timerE1.stop()
        timerE1.reset()
    }
    else if(e1.x >= 1250)
    {
         timerE1.start()
    }
    
    if(e2.x <= -350)
    {
        e2.x = 1325;
        timerE2.stop()
        timerE2.reset()
    }
    else if(e2.x >= 1325)
    {
         timerE2.start()
    }
    
    
    if(e3.x <= -450)
    {
        e3.x = 1400;
        timerE3.stop()
        timerE3.reset()
    }
    else if(e3.x >= 1400)
    {
         timerE3.start()
    }
    
    
    if(e4.x <= -550)
    {
        e4.x = 1475;
        timerE4.stop()
        timerE4.reset()
    }
    else if(e4.x >= 1475)
    {
         timerE4.start()
    }
    
    
    if(e5.x <= -650)
    {
        e5.x = 1550;
        timerE5.stop()
        timerE5.reset()
    }
    else if(e5.x >= 1550)
    {
         timerE5.start()
    }
    
    
    if(e6.x <= -750)
    {
        e6.x = 1625;
        timerE6.stop()
        timerE6.reset()
    }
    else if(e6.x >= 1625)
    {
         timerE6.start()
    }
    
    e1.x -= 3;  
    e2.x -= 3;
    e3.x -= 3;  
    e4.x -= 3;
    e5.x -= 3;  
    e6.x -= 3;
    }
    

    【讨论】:

    • Glitcher 非常感谢您的帮助。你能帮我解决另一个问题吗?我希望 16 个影片剪辑进入舞台,水平的,一次一个,但随机的,这个过程应该继续。我已经编写了代码,但需要编辑和修改。你的邮件ID请!!
    • Glitcher,我希望将 .fla 文件发送给您,以便您了解我正在努力传达的内容。
    • 将您的代码粘贴到 pastebin.com 并在此处评论我的链接。我去看看
    • 它是私人的:S请公开:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 2014-01-28
    • 2016-05-17
    • 1970-01-01
    相关资源
    最近更新 更多