声音层级加载

package coma {
    import flash.display.Sprite;
    import flash.media.Sound;
    import flash.net.URLRequest;
    import flash.display.MovieClip;
    import flash.media.SoundChannel;
    import flash.display.SimpleButton;
    import flash.events.MouseEvent;
    import flash.display.Stage;

    public class MyMusic extends Sprite {

        public static var urlRe:URLRequest;
        public static var urlSt:String;

        public static var sound:Sound;
        public static var soundChannel:SoundChannel;
        public static var soundPosition:Number=0;
        public static var isSoundPlay:Boolean=true;
        public static var _stage:Stage


        public function MyMusic( ___stage:Stage) {
            super()
            _stage=___stage
            sound=new Sound ();
            soundChannel=new SoundChannel ();
        }
        //===========初始声音===================================
        public static function initialSound(_urlSt:String ) {
            var str=_stage.loaderInfo.url
            var str1:int= str.lastIndexOf("/");
            var str2:String=str.slice(0,str1+1)
            var str3:String=str.substring(str1+1)
            trace(str1)
            trace(str2)
            trace(str3)
            soundChannel.stop();
            sound=new Sound ();
            urlRe=new URLRequest (str2+"music/"+_urlSt+".mp3");
            soundChannel=new SoundChannel ();
            sound.load(urlRe);
            soundChannel=sound.play();
        }

        //===========在暂停的地方继续播放===============================================================================
        //暂停
        public static function pauseFuntion() {
            soundPosition=soundChannel.position;
            soundChannel.stop();
            isSoundPlay=true;
        }
        //播放;
        public static function playFuntion() {
            if (isSoundPlay) {
                soundChannel=sound.play(soundPosition);
                isSoundPlay=false;
            }
        }
    }
}

 

posted on 2018-09-12 14:34  zqiang0803  阅读(124)  评论(0编辑  收藏  举报

导航