2013-10-24 47 views
0

任何人都可以请告诉我如何编写代码以使影片剪辑进入舞台并启动定时器当影片剪辑移出舞台时停止。触发定时器作为影片剪辑进入舞台,并在影片剪辑离开舞台时停止它们[as3]

我在舞台外放置了某些影片剪辑,并使它们在舞台上从右向左移动(当然,在x轴上,一次3像素)。当每个影片剪辑进入舞台时,应该触发相关的定时器。当定时器被触发时,它将每隔两秒钟开始播放一个特定的音频片段。当影片剪辑移出舞台时,计时器应停止,以便MP3音频也将停止。 KINDLY SUGGEST SOME 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; 
} 

回答

0

你几乎做已经:

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

Glitcher非常感谢您的帮助。你能帮助我解决另一个问题吗?我希望16个电影剪辑一次一个水平地进入舞台,但是随机播放,并且流程应该继续。我编写了代码,但需要编辑和修改。乌尔邮件编号请! – user2835788

+0

Glitcher,我希望向您发送.fla文件,以便您了解我正在努力传达的内容。 – user2835788

+0

将您的代码粘贴到pastebin.com并在此处评论我的链接。我会看看 – Glitcher