/ Published in: ActionScript 3
Expand |
Embed | Plain Text
package { import flash.display.*; import flash.media.Sound; import flash.media.SoundChannel; import flash.media.SoundMixer; import flash.net.URLLoader; import flash.net.URLRequest; import flash.text.TextField; import flash.events.MouseEvent; import flash.events.Event; import flash.text.TextFieldAutoSize; import flash.utils.ByteArray; import flash.external.*; public class CaribouPlayer extends Sprite { public static var snd:Sound = new Sound(); public static var channel:SoundChannel = new SoundChannel(); public static var ba:ByteArray = new ByteArray(); public static var array:Array; public static var button:TextField = new TextField(); public static var myTitle:TextField = new TextField(); public static var myEqua:MovieClip = new MovieClip(); public static var a:Number=0; public static var myFile:String=""; public static var myHtmlLinkHandler:String=""; public static var myHtmlSWFDiv:String=""; public static var myID:Number; public function CaribouPlayer() { if (root.loaderInfo.parameters["dFile"]!=null) { myFile=root.loaderInfo.parameters["dFile"]; } if (root.loaderInfo.parameters["dLinkID"]!=null) { myHtmlLinkHandler=root.loaderInfo.parameters["dLinkID"]; } if (root.loaderInfo.parameters["dSWF"]!=null) { myHtmlSWFDiv=root.loaderInfo.parameters["dSWF"]; } if (root.loaderInfo.parameters["dID"]!=null) { var myResult:String=root.loaderInfo.parameters["dID"]; var idNum=int(myResult); myID=idNum; } myEqua = Equa ; var req:URLRequest=new URLRequest('audio/foundout.mp3'); snd.load(req); channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); button.x=200; button.y=200; button.alpha=0; button.text="PLAY"; button.border=true; button.background=true; button.selectable=false; button.autoSize=TextFieldAutoSize.CENTER; myTitle.x=200; myTitle.y=200; myTitle.text="TEST FIELD"; myTitle.alpha=1; myTitle.border=true; myTitle.background=true; myTitle.selectable=false; myTitle.autoSize=TextFieldAutoSize.CENTER; // button.addEventListener(MouseEvent.CLICK, clickHandler); //button.mouseEnabled = true; //button.buttonMode = true; this.addChild(button); this.addChild(myTitle); this.addEventListener(Event.ENTER_FRAME, spectrum); clickHandler(); } ExternalInterface.addCallback("clickHandler", clickHandler); public static function clickHandler():void { var pausePosition:int=channel.position; myTitle.text="theyClikedme"; if (button.text=="PLAY") { channel=snd.play(pausePosition); button.text="PAUSE"; flash.external.ExternalInterface.call("writeButton", "PAUSE", myHtmlLinkHandler, myHtmlSWFDiv); } else { channel.stop(); button.text="PLAY"; flash.external.ExternalInterface.call("writeButton", "PLAY", myHtmlLinkHandler, myHtmlSWFDiv); } } public static function soundCompleteHandler(e:Event):void { channel.stop(); button.text="PLAY"; myTitle.alpha=0; trace('sound finished'); flash.external.ExternalInterface.call("writeButton", "PLAY", myHtmlLinkHandler, myHtmlSWFDiv); } public static function spectrum(event:Event) { a=0; //graphics.clear(); SoundMixer.computeSpectrum(ba,true,0); a=ba.readFloat(); var num:Number=Math.round(a*9); //trace(num+1) myEqua.gotoAndStop(num+1); } } }
You need to login to post a comment.
