/ Published in: ActionScript 3
Simple yet effective way to create a horizontal slider to controll the volume of your sound channel
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var maxMove:Number =50; var bounds:Rectangle = new Rectangle(this.volumeSlider.x, this.volumeSlider.y, -maxMove, 0); var scrolling:Boolean = false; function startScroll (e:Event):void { scrolling = true; this.volumeSlider.startDrag (false,bounds); } function stopScroll (e:Event):void { scrolling = false; this.volumeSlider.stopDrag (); } function enterHandler (e:Event):void { if (scrolling == true) { MovieClip(this.root).setVolume(1-((bounds.x-this.volumeSlider.x)/maxMove)); } } function setVolume(vol:Number){ var mod:SoundTransform = new SoundTransform(); mod.volume = vol; mp3Channel.soundTransform = mod; //apply to yout mp3Channel } addEventListener (Event.ENTER_FRAME, enterHandler); this.volumeSlider.addEventListener (MouseEvent.MOUSE_DOWN, startScroll); stage.addEventListener (MouseEvent.MOUSE_UP, stopScroll);