In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

sound test

Get Adobe Flash player
by yambian 10 Mar 2010
    Embed
/**
 * Copyright yambian ( http://wonderfl.net/user/yambian )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kOjF
 */

package {
    import flash.display.Sprite;
    import flash.media.*;
    import flash.events.*;
    import flash.net.*;
    import flash.ui.Keyboard;
    public class FlashTest extends Sprite {
        private var mySound:Sound;
        private var channel:SoundChannel;
        private var play:Boolean;
        public function FlashTest() {
            mySound = new Sound();
            //http://upload.wikimedia.org/wikipedia/en/f/fe/Korobeiniki.mid
            mySound.load(new URLRequest("http://yambi.mydns.jp/resource/Korobeiniki.mp3")); 
            channel = mySound.play(0, int.MAX_VALUE);
            play = true;
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        }
       	private function onKeyDown(event:KeyboardEvent):void{
		if (event.keyCode == Keyboard.SPACE) stop();
		if (event.keyCode == Keyboard.ENTER) stop();
	}
	private function stop():void{
		var cp:int = channel.position;
		if(play)channel.stop();
		else channel = mySound.play(cp);
		play = !play;
	}
    }
}