Posted By

julianvalencia on 09/20/10


Tagged


Versions (?)

caribou player


 / Published in: ActionScript 3
 

  1. package {
  2. import flash.display.*;
  3. import flash.media.Sound;
  4. import flash.media.SoundChannel;
  5. import flash.media.SoundMixer;
  6. import flash.net.URLLoader;
  7. import flash.net.URLRequest;
  8. import flash.text.TextField;
  9. import flash.events.MouseEvent;
  10. import flash.events.Event;
  11. import flash.text.TextFieldAutoSize;
  12. import flash.utils.ByteArray;
  13. import flash.external.*;
  14.  
  15.  
  16. public class CaribouPlayer extends Sprite {
  17.  
  18.  
  19. public static var snd:Sound = new Sound();
  20. public static var channel:SoundChannel = new SoundChannel();
  21. public static var ba:ByteArray = new ByteArray();
  22. public static var array:Array;
  23.  
  24.  
  25. public static var button:TextField = new TextField();
  26.  
  27. public static var myTitle:TextField = new TextField();
  28.  
  29. public static var myEqua:MovieClip = new MovieClip();
  30. public static var a:Number=0;
  31.  
  32. public static var myFile:String="";
  33. public static var myHtmlLinkHandler:String="";
  34. public static var myHtmlSWFDiv:String="";
  35. public static var myID:Number;
  36.  
  37.  
  38.  
  39. public function CaribouPlayer() {
  40.  
  41. if (root.loaderInfo.parameters["dFile"]!=null) {
  42. myFile=root.loaderInfo.parameters["dFile"];
  43.  
  44. }
  45.  
  46. if (root.loaderInfo.parameters["dLinkID"]!=null) {
  47. myHtmlLinkHandler=root.loaderInfo.parameters["dLinkID"];
  48.  
  49. }
  50.  
  51. if (root.loaderInfo.parameters["dSWF"]!=null) {
  52. myHtmlSWFDiv=root.loaderInfo.parameters["dSWF"];
  53.  
  54. }
  55.  
  56. if (root.loaderInfo.parameters["dID"]!=null) {
  57. var myResult:String=root.loaderInfo.parameters["dID"];
  58. var idNum=int(myResult);
  59. myID=idNum;
  60.  
  61. }
  62.  
  63. myEqua = Equa
  64.  
  65.  
  66.  
  67. ;
  68. var req:URLRequest=new URLRequest('audio/foundout.mp3');
  69. snd.load(req);
  70.  
  71. channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
  72.  
  73. button.x=200;
  74. button.y=200;
  75. button.alpha=0;
  76. button.text="PLAY";
  77. button.border=true;
  78. button.background=true;
  79. button.selectable=false;
  80. button.autoSize=TextFieldAutoSize.CENTER;
  81.  
  82. myTitle.x=200;
  83. myTitle.y=200;
  84.  
  85. myTitle.text="TEST FIELD";
  86. myTitle.alpha=1;
  87. myTitle.border=true;
  88. myTitle.background=true;
  89. myTitle.selectable=false;
  90. myTitle.autoSize=TextFieldAutoSize.CENTER;
  91.  
  92.  
  93. // button.addEventListener(MouseEvent.CLICK, clickHandler);
  94. //button.mouseEnabled = true;
  95. //button.buttonMode = true;
  96.  
  97.  
  98.  
  99. this.addChild(button);
  100. this.addChild(myTitle);
  101. this.addEventListener(Event.ENTER_FRAME, spectrum);
  102.  
  103.  
  104. clickHandler();
  105. }
  106.  
  107.  
  108.  
  109. ExternalInterface.addCallback("clickHandler", clickHandler);
  110.  
  111.  
  112.  
  113.  
  114. public static function clickHandler():void {
  115. var pausePosition:int=channel.position;
  116.  
  117. myTitle.text="theyClikedme";
  118.  
  119. if (button.text=="PLAY") {
  120. channel=snd.play(pausePosition);
  121. button.text="PAUSE";
  122. flash.external.ExternalInterface.call("writeButton", "PAUSE", myHtmlLinkHandler, myHtmlSWFDiv);
  123.  
  124. } else {
  125. channel.stop();
  126. button.text="PLAY";
  127. flash.external.ExternalInterface.call("writeButton", "PLAY", myHtmlLinkHandler, myHtmlSWFDiv);
  128. }
  129.  
  130.  
  131. }
  132.  
  133.  
  134.  
  135. public static function soundCompleteHandler(e:Event):void {
  136. channel.stop();
  137. button.text="PLAY";
  138. myTitle.alpha=0;
  139. trace('sound finished');
  140. flash.external.ExternalInterface.call("writeButton", "PLAY", myHtmlLinkHandler, myHtmlSWFDiv);
  141.  
  142.  
  143. }
  144.  
  145. public static function spectrum(event:Event) {
  146. a=0;
  147. //graphics.clear();
  148. SoundMixer.computeSpectrum(ba,true,0);
  149. a=ba.readFloat();
  150. var num:Number=Math.round(a*9);
  151. //trace(num+1)
  152. myEqua.gotoAndStop(num+1);
  153. }
  154.  
  155.  
  156. }
  157. }

Report this snippet  

You need to login to post a comment.