Posted By

youngster on 11/10/10


Tagged

as3soundobjectcontrols


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

sexyflash
onemanstudio


SoundObject


 / Published in: ActionScript 3
 

  1. import flash.media.Sound;
  2. import flash.media.SoundChannel;
  3. import flash.net.URLLoader;
  4. import flash.net.URLRequest;
  5. import flash.events.Event;
  6. import flash.events.MouseEvent;
  7. import flash.geom.Rectangle;
  8. import flash.media.SoundTransform;
  9. import fl.controls.CheckBox;
  10.  
  11. var mySong:Sound=new Sound()
  12. var sc:SoundChannel
  13. var pos:Number=0
  14. var vol:Number
  15. var pan:Number
  16.  
  17. p_txt.text="0"
  18. sBar_mc.rect_mc.scaleX=0
  19.  
  20. mySong.load(new URLRequest("1.mp3"))
  21. mySong.addEventListener(Event.COMPLETE,time)
  22. function time(event:Event){
  23. d_txt.text=Math.round(((mySong.length/1000)/60)*100)/100+"mins"
  24. }
  25. play_btn.addEventListener(MouseEvent.CLICK,playit)
  26. function playit(event:MouseEvent){
  27. sc=mySong.play(pos,0)
  28. }
  29. stop_btn.addEventListener(MouseEvent.CLICK,stopit)
  30. function stopit(event:MouseEvent){
  31. pos=0
  32. sc.stop()
  33. }
  34. pause_btn.addEventListener(MouseEvent.CLICK,pauseit)
  35. function pauseit(event:MouseEvent){
  36. pos=sc.position
  37. sc.stop()
  38. }
  39.  
  40.  
  41. stage.addEventListener(Event.ENTER_FRAME,update)
  42. function update(event:Event){
  43. if(sc!=null){
  44. /*p_txt.text=Math.round((sc.position/1000)/60)+" sec"*/
  45. p_txt.text=Math.round(((sc.position/1000)/60)*100)/100+" sec"
  46.  
  47. sBar_mc.rect_mc.scaleX=sc.position/mySong.length
  48. sBar_mc.sbr_mc.x=sBar_mc.rect_mc.width
  49. sBar_mc.sbr_mc.y=0
  50.  
  51. pan=Math.round(pan_mc.rect_mc.x)-100
  52. if(cb.selected==false){
  53. vol=slider_mc.rect_mc.x/100
  54. }
  55. var st:SoundTransform=new SoundTransform(vol,pan)
  56. sc.soundTransform=st
  57. }
  58.  
  59. slider_mc.num_txt.text=Math.round((slider_mc.rect_mc.x*100)/200)
  60. pan_mc.num_txt.text=Math.round(pan_mc.rect_mc.x)-100
  61. }
  62.  
  63.  
  64. sBar_mc.sbr_mc.buttonMode=true
  65. slider_mc.rect_mc.buttonMode=true
  66. pan_mc.rect_mc.buttonMode=true
  67.  
  68. var myRect:Rectangle=new Rectangle(0,0,200,0)
  69.  
  70. sBar_mc.sbr_mc.addEventListener(MouseEvent.MOUSE_DOWN,stsdrag)
  71. function stsdrag(event:MouseEvent){
  72. sBar_mc.sbr_mc.startDrag(false,myRect)
  73. }
  74.  
  75. /********************Creating volume slider****************/
  76.  
  77. var sliderRect:Rectangle=new Rectangle(0,0,200,0)
  78. slider_mc.rect_mc.addEventListener(MouseEvent.MOUSE_DOWN,stlDrag)
  79. function stlDrag(event:MouseEvent){
  80. slider_mc.rect_mc.startDrag(false,sliderRect)
  81. cb.selected=false
  82. }
  83. stage.addEventListener(MouseEvent.MOUSE_UP,spDrag)
  84. function spDrag(event:MouseEvent){
  85. slider_mc.rect_mc.stopDrag()
  86. pan_mc.rect_mc.stopDrag()
  87. sBar_mc.sbr_mc.stopDrag()
  88. }
  89.  
  90. /**************pannning************************/
  91.  
  92. var panRect:Rectangle=new Rectangle(0,0,200,0)
  93. pan_mc.rect_mc.addEventListener(MouseEvent.MOUSE_DOWN,stpDrag)
  94. function stpDrag(event:MouseEvent){
  95. pan_mc.rect_mc.startDrag(false,panRect)
  96. }
  97.  
  98. /************* Check box to mute sound **********/
  99.  
  100. var cb:CheckBox=new CheckBox()
  101. addChild(cb)
  102.  
  103. cb.x=670
  104. cb.y=140
  105. cb.label="Mute"
  106.  
  107. cb.addEventListener(Event.CHANGE,mute)
  108. function mute(event:Event){
  109. if(cb.selected==true){
  110. vol=0
  111. event.target.label="unMute"
  112. }else{
  113. event.target.label="Mute"
  114. }
  115. }

Report this snippet  

You need to login to post a comment.