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

Beat Maker

Create songs with beat maker!
Get Adobe Flash player
by FelixT 14 Nov 2010
/**
 * Copyright FelixT ( http://wonderfl.net/user/FelixT )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1Ami
 */

package {
    import flash.display.AVM1Movie;
    import flash.display.Sprite;
    import flash.net.URLRequest;
    import flash.media.Sound;  
    import flash.media.SoundChannel;  
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.events.MouseEvent;
    import flash.errors.IOError;
    import flash.events.IOErrorEvent;
    

    public class Main extends Sprite {
        
        private var sound:Sound;
        private var s:Sound;
        private var channel:SoundChannel;
        private var c:SoundChannel;
        private var b:TextField = new TextField();
        private var button:TextField = new TextField();
        
        public function Main() {
            sound = new Sound(new URLRequest("http://www.looperman.com/00_assets/loops/265235/looperman_265235_38084_drum%20loop%201.mp3")); // Load Beat Sample
            button.x = 10;
            button.y = 10;
            button.text = "Start Beat";
            button.border = true;
            button.background = true;
            button.selectable = false;
            button.autoSize = TextFieldAutoSize.LEFT;
            
            button.addEventListener(MouseEvent.CLICK, clickHandler);
            
            s = new Sound(new URLRequest("http://www.platinumloops.com/demo/percussion/dj_scratches_vinyl_acrobatics_v1/mp3/phrasescratch90d.mp3")); // Load Scratch Sample
            b.x = 100;
            b.y = 10;
            b.text = "Start Scratch";
            b.border = true;
            b.background = true;
            b.selectable = false;
            b.autoSize = TextFieldAutoSize.LEFT;

            b.addEventListener(MouseEvent.CLICK, clickHandler); // How do I make the two sounds not play together?

            this.addChild(button);
            this.addChild(b);
        }

        private function clickHandler(e:MouseEvent):void {
            

            if(button.text == "Start Beat") {

                channel = sound.play(0,99999);       


                button.text = "Stop Beat";
            }
            else if(button.text == "Stop Beat") {
                    
                try {
                    channel.stop();
                    button.text = "Start Beat";
                }
                catch (error:IOError) 
                   {button.text = "Error" 
                   }
            }
            
                       

                   
                   if(b.text == "Start Scratch") {

                c = s.play(0,99999);       


                b.text = "Stop Scratch";
            }
            else if(b.text == "Stop Scratch") {
                    
                try {
                    c.stop();
                    b.text = "Start Scratch";
                }
                catch (error:IOError) 
                   {b.text = "Error"
                  } 
               }
            }
        }
    }