Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var music:Sound = new Sound();
- music.load(new URLRequest("music.mp3"));
- var channel:SoundChannel = new SoundChannel();
- music.addEventListener(Event.COMPLETE, soundComplete);
- function soundComplete(e:Event):void
- {
- //Remove COMPLETE event listener
- music.removeEventListener(Event.COMPLETE, soundComplete);
- //Play the sound
- channel = music.play();
- //Add the ENTER_FRAME event listener
- addEventListener(Event.ENTER_FRAME, checkPosition);
- };
- function checkPosition(e:Event):void
- {
- //Divide the channel current position by the lenght of the loaded sound
- //multiply by 100, and round to get the percentage.
- var percentage:int = Math.floor((channel.position / music.length) * 100);
- //If percentage == 50, the sound is at half.
- if(percentage == 50)
- {
- trace("Sound is at half");
- }
- trace(percentage+ "%");
- };
- channel.addEventListener(Event.SOUND_COMPLETE, function(e:Event):void
- {
- //Sound finished playing, what to do?
- //Remove the checkPosition event listener
- removeEventListener(Event.ENTER_FRAME, checkPosition);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement