/ Published in: ActionScript 3
Expand |
Embed | Plain Text
import flash.media.Sound; import flash.media.SoundChannel; import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.media.SoundTransform; import fl.controls.CheckBox; var mySong:Sound=new Sound() var sc:SoundChannel var pos:Number=0 var vol:Number var pan:Number p_txt.text="0" sBar_mc.rect_mc.scaleX=0 mySong.load(new URLRequest("1.mp3")) mySong.addEventListener(Event.COMPLETE,time) function time(event:Event){ d_txt.text=Math.round(((mySong.length/1000)/60)*100)/100+"mins" } play_btn.addEventListener(MouseEvent.CLICK,playit) function playit(event:MouseEvent){ sc=mySong.play(pos,0) } stop_btn.addEventListener(MouseEvent.CLICK,stopit) function stopit(event:MouseEvent){ pos=0 sc.stop() } pause_btn.addEventListener(MouseEvent.CLICK,pauseit) function pauseit(event:MouseEvent){ pos=sc.position sc.stop() } stage.addEventListener(Event.ENTER_FRAME,update) function update(event:Event){ if(sc!=null){ /*p_txt.text=Math.round((sc.position/1000)/60)+" sec"*/ p_txt.text=Math.round(((sc.position/1000)/60)*100)/100+" sec" sBar_mc.rect_mc.scaleX=sc.position/mySong.length sBar_mc.sbr_mc.x=sBar_mc.rect_mc.width sBar_mc.sbr_mc.y=0 pan=Math.round(pan_mc.rect_mc.x)-100 if(cb.selected==false){ vol=slider_mc.rect_mc.x/100 } var st:SoundTransform=new SoundTransform(vol,pan) sc.soundTransform=st } slider_mc.num_txt.text=Math.round((slider_mc.rect_mc.x*100)/200) pan_mc.num_txt.text=Math.round(pan_mc.rect_mc.x)-100 } sBar_mc.sbr_mc.buttonMode=true slider_mc.rect_mc.buttonMode=true pan_mc.rect_mc.buttonMode=true var myRect:Rectangle=new Rectangle(0,0,200,0) sBar_mc.sbr_mc.addEventListener(MouseEvent.MOUSE_DOWN,stsdrag) function stsdrag(event:MouseEvent){ sBar_mc.sbr_mc.startDrag(false,myRect) } /********************Creating volume slider****************/ var sliderRect:Rectangle=new Rectangle(0,0,200,0) slider_mc.rect_mc.addEventListener(MouseEvent.MOUSE_DOWN,stlDrag) function stlDrag(event:MouseEvent){ slider_mc.rect_mc.startDrag(false,sliderRect) cb.selected=false } stage.addEventListener(MouseEvent.MOUSE_UP,spDrag) function spDrag(event:MouseEvent){ slider_mc.rect_mc.stopDrag() pan_mc.rect_mc.stopDrag() sBar_mc.sbr_mc.stopDrag() } /**************pannning************************/ var panRect:Rectangle=new Rectangle(0,0,200,0) pan_mc.rect_mc.addEventListener(MouseEvent.MOUSE_DOWN,stpDrag) function stpDrag(event:MouseEvent){ pan_mc.rect_mc.startDrag(false,panRect) } /************* Check box to mute sound **********/ var cb:CheckBox=new CheckBox() addChild(cb) cb.x=670 cb.y=140 cb.label="Mute" cb.addEventListener(Event.CHANGE,mute) function mute(event:Event){ if(cb.selected==true){ vol=0 event.target.label="unMute" }else{ event.target.label="Mute" } }
You need to login to post a comment.
