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

SiONコトハジメ – 01

SiONコトハジメ
外部MP3を読み込んで、setSamplerSound/setMP3Voice/setPCMVoiceするだけのサンプルです.
Get Adobe Flash player
by axcel_work 16 May 2011
/**
 * Copyright axcel_work ( http://wonderfl.net/user/axcel_work )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/w0Cf
 */

package {
    import com.bit101.components.Label;
    import com.bit101.components.PushButton;

    import org.si.sion.SiONDriver;
    import org.si.sion.SiONVoice;

    import flash.display.Sprite;
    import flash.events.Event;
    import flash.media.Sound;
    import flash.net.URLRequest;

    /**
     * @author axcelwork
     */
    public class Index extends Sprite {
        private var driver:SiONDriver = new SiONDriver();

        private var source1:Sound = new Sound();
        private var source2:Sound = new Sound();
        private var source3:Sound = new Sound();

        private var isSound1:Boolean = false;
        private var isSound2:Boolean = false;
        private var isSound3:Boolean = false;

        
        /**
         * 
         */
        public function Index() {
            
            if(stage) this.atInit();
            else this.addEventListener(Event.ADDED_TO_STAGE, atInit);
        }

        private function atInit(e:Event = null):void {
            trace("[Info] スタート");
            
            this.stage.scaleMode = "noScale";
            this.stage.align = "left";
            
            driver.play();
            
            new Label(this, 0, 0, "SiONDriver:setSamplerSound");
            new Label(this, 0, 40, "SiONDriver:setMP3Voice");
            new Label(this, 0, 100, "SiONDriver:setPCMVoice");

            var btn1:PushButton = new PushButton(this, 140, 0, "noteOn", btn1Click);
            btn1.width = 50;
            btn1.toggle = true;

            var btn2:PushButton = new PushButton(this, 140, 50, "noteOn", btn2Click);
            btn2.width = 50;
            btn2.toggle = true;

            var btn3:PushButton = new PushButton(this, 140, 100, "noteOn", btn3Click);
            btn3.width = 50;
            btn3.toggle = true;
        }

        private function btn1Click(e:Event):void {
            this.isSound1 = !this.isSound1;
            
            if(this.isSound1) {
                this.source1 = new Sound();
                this.source1.load(new URLRequest("http://shift-style.org/labo/sion/select_003.mp3"));
                this.source1.addEventListener(Event.COMPLETE, btn1Complete);
            } else {
                driver.noteOff(69);
            }
        }
        private function btn1Complete(e:Event):void {
            driver.setSamplerSound(60, source1);
            driver.noteOn(60, new SiONVoice(10));
        }

        private function btn2Click(e:Event):void {
            this.isSound2 = !this.isSound2;
            
            if(this.isSound2) {
                this.source2 = new Sound();
                this.source2.load(new URLRequest("http://shift-style.org/labo/sion/boot_002.mp3"));
                this.source2.addEventListener(Event.COMPLETE, btn2Complete);
            } else {
                driver.noteOff(69);
            }
        }
        private function btn2Complete(e:Event):void {
            var pcmVoice:SiONVoice = new SiONVoice();
            pcmVoice.setMP3Voice(source2);
            driver.noteOn(69, pcmVoice, 0, 0, 1, 100);
        }
        
        private function btn3Click(e:Event):void {
            this.isSound3 = !this.isSound3;
            
            if(this.isSound3) {
                this.source3 = new Sound();
                this.source3.load(new URLRequest("http://shift-style.org/labo/sion/grab.mp3"));
                this.source3.addEventListener(Event.COMPLETE, btn3Complete);
            } else {
                driver.noteOff(69);
            }
        }
        private function btn3Complete(e:Event):void {
            var pcmVoice:SiONVoice = new SiONVoice();
            pcmVoice.setPCMVoice(source3);
            driver.noteOn(69, pcmVoice, 0, 0, 1, 101);
        }
    }
}