package { import flash.display.*; import flash.media.*; //import fl.controls.*; import fl.events.*; //import fl.controls.*; import flash.events.*; import flash.net.*; import flash.text.*; import flash.ui.*; public class Sounds extends Sprite { private var soundChannel:SoundChannel; private var _soundTransform:SoundTransform; private var volumeNum:Number; private var url:String; private var request:URLRequest; private var sound:Sound; //private var myLabel:Label; //private var thickness:Number = 1; //private var mySlider:Slider; private var flag:Boolean; private var count:int; private var randomNum:int; public function Sounds(randomNum:int) { this.randomNum=randomNum; volumeNum = 1; recursion(); url = "sound/music" + randomNum + ".mp3"; request = new URLRequest(url); sound = new Sound ; sound.load(request); sound.addEventListener(Event.COMPLETE,completeHandler); /*myLabel= new Label(); myLabel.autoSize = TextFieldAutoSize.LEFT; myLabel.text = ""; myLabel.move(100, 30); addChild(myLabel); mySlider = new Slider(); mySlider.snapInterval = 1; mySlider.minimum = 0; mySlider.maximum = 100; mySlider.value = 100; mySlider.addEventListener(SliderEvent.THUMB_DRAG, thumbDragHandler); mySlider.move(myLabel.x, myLabel.y + myLabel.height); addChild(mySlider);*/ //this.addEventListener(KeyboardEvent.KEY_DOWN,onkeyDown); } public function onkeyDown():void { if (flag) { mute(); recursion(); url = "sound/music" + randomNum + ".mp3"; trace(url); request = new URLRequest(url); sound = new Sound ; sound.load(request); sound.addEventListener(Event.COMPLETE,completeHandler); } } public function mute():void { soundChannel.stop(); } public function _play():void { soundChannel = sound.play(); } private function recursion():void { randomNum = Math.round(Math.random() * 2 + 1); if (count != randomNum) { count = randomNum; } else { recursion(); } } private function completeHandler(e:Event):void { sound.removeEventListener(Event.COMPLETE,completeHandler); flag = true; _play(); _soundTransform = new SoundTransform(volumeNum,0); addEventListener(Event.ENTER_FRAME,enterFrameHandler); } private function enterFrameHandler(e:Event):void { soundChannel.soundTransform = _soundTransform; } /*private function thumbDragHandler(e:SliderEvent):void { myLabel.text = e.type + ": " + thickness; thickness = e.value; _soundTransform.volume = e.value / 100; }*/ } }