troubleshooting Question

Checking to see if sound sound file has finished on timeline

Avatar of CAE5942
CAE5942 asked on
Adobe FlashScripting LanguagesApache Flex
4 Comments3 Solutions315 ViewsLast Modified:
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
Join our community to see this answer!
Unlock 3 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros