package com.dnecklesportfolio.sound{ import gs.TweenMax; import flash.media.*; import flash.net.*; import flash.events.*; import flash.display.*; import flash.events.EventDispatcher; import flash.events.Event; import Intro public class MuteButton extends MovieClip { public var someSound:Sound; public var someChannel:SoundChannel = new SoundChannel(); public var somePosition:Number; public var actualMinutes:Number; public var actualSeconds:Number; public var convertedMinutes:Number; public var convertedSeconds:Number; public var muteState:Boolean; public var _rootCanvas:Intro; public static const LOADED:String = "ON_LOADED"; public function MuteButton($rootCanvas:Intro,$sound:Sound) { _rootCanvas = $rootCanvas someSound = $sound //var s:Sound = new Sound(); actualMinutes = 2; actualSeconds = 25; convertedMinutes = actualMinutes * 60000; convertedSeconds = actualSeconds * 1000; muteState = false; somePosition = convertedMinutes + convertedSeconds; this.gotoAndStop(2); this.addEventListener(MouseEvent.MOUSE_UP, _myStartSound); this.buttonMode = true //s.load(new URLRequest("song.mp3"),context); someChannel = someSound.play(somePosition,5,null); } private function _myStartSound(event:MouseEvent):void { if ( muteState == false ) { muteState = true; _setVolume(0); this.gotoAndStop(1); } else { muteState = false; _setVolume(1); this.gotoAndStop(2); } } function onIOError(event:IOErrorEvent) { trace("The sound could not be loaded: " + event.text); } private function _setVolume(volume:Number):void { //trace("setVolume: " + volume.toFixed(2)); var transform:SoundTransform = someChannel.soundTransform; transform.volume = volume; someChannel.soundTransform = transform; } } }