Link to home
Start Free TrialLog in
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

ASKER CERTIFIED SOLUTION
Avatar of blue-genie
blue-genie
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CAE5942
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.