0
votes

Can anyone please tell me how to write the code for making a timer to start when a movie clip enters the stage and the timer to stop when the movie clip moves out of the stage.

I have placed certain movie clips outside the stage and have made them move from right to left across the stage (of course, on an x axis, 3 pixels at a time). As each movie clip enters the stage, a related timer should be triggered. When the timer is triggered, it will start playing a specific audio clip on every two second interval. And when the movie clip moves out of the stage, the timer should stop, so that the mp3 audio will also be stopped. KINDLY SUGGEST SOME NON-OOP WAYS OF DOING IT. Its just the "triggering" and "stopping" part that i need.

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

1 Answers

0
votes

You're almost doing it already:

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