Avatar of CAE5942
CAE5942
 asked on

Checking to see if sound sound file has finished on timeline

Hi everyone,

I'm using the actionscript code below to load a .mp3 file and then it checks to see when the sound is complete and then runs a function which fades another movieclip.

The code works as expected but as I need to synchronise another animation with the sound, I thought it would be easier to have the sound file on the timeline itself instead of loading it using actionscript. If I do it that way though, I still need to use actionscript to check when the sound has finished playing so that the "advertEnd" function can run.

Can someone tell me how I'd revise the code below so that it only checks to see if the sound has finished and runs the function?

Appreciate any advice.
var req:URLRequest = new URLRequest("sound.mp3");
var sound:Sound = new Sound();
var channel:SoundChannel;

function soundLoaded(event:Event):void
{
	channel = sound.play();
    if( !channel.hasEventListener( Event.SOUND_COMPLETE ) ){
            channel.addEventListener( Event.SOUND_COMPLETE, advertEnd );
       }
}

sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(req);


function advertEnd(e:Event):void
	{
		trace("FLV has ended");
		stage.addEventListener(Event.ENTER_FRAME, fadeAdvert);
	}

Open in new window

Adobe FlashScripting LanguagesApache Flex

Avatar of undefined
Last Comment
CAE5942

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
blue-genie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
dgofman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
ayteq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CAE5942

ASKER
Thanks for all the replies,

Sorry I haven't responded until now as I've been really snowed under with work. I plan to test out the different options and I'll get back to you as soon as I can.
Your help has saved me hundreds of hours of internet surfing.
fblack61