Hey folks I have a sound manager class that I use in my game to load all my sounds, which works fine for the most part. But I created a volume settings which allows the user to adjust the volume on specific sounds in the game for example the back ground music and voice overs. The problem I am having is communicating between the classes. The functionality is there for the most part but when I adjust something in one class I cant get another class to update.
So in my [FONT=monospace]SettingsController which is the last code block in this post I am trying to update the volume from my sound manager class when the user adjusts the volume handle.[/FONT]
Any help would be greatly appreciated.
In my sound manager class I have the following:
package com.gamehelp.sounds
{
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;
import flash.events.TimerEvent;
import flash.media.*;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.utils.Timer;
public class SoundManager
{
private var _xmlsource :XMLList;
public var mp3Loader :MP3Loader;
public var themeSound :Object;
public var gameSound :Object;
// theme song audio
public var themeAudioURL :String;
public function SoundManager(xmlsource:XMLList)
{
_xmlsource = xmlsource;
_audioPlaying = false;
}
public function initThemeAudio():void
{
themeAudioURL = _xmlsource.themesong.@url;
}
public function playThemeAudio(audioURL:String, whatToLoad:Object):void
{
whatToLoad = themeSound;
if(!_audioPlaying)
{
_audioPlaying = true;
themeSound = new MP3Loader(audioURL, {name:"theme_sound", autoPlay:true, repeat:-1});
themeSound.load();
}
}
}
}
This is the class where the window that contains the controls is instantiated: Basically when the user clicks on the settings button it brings up a window
package com.gamehelp.controllers.ui
{
import com.gamehelp.controllers.windows.SettingsController;
import com.gamehelp.controls.SettingsOption;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
public class SettingsOptionController extends Sprite
{
private var _scl :SettingsOption;
private var _settingsWinController :SettingsController;
private var _isWinActive :Boolean = false;
private static const PADDING :Number = 3;
private static const DURA :Number = .65;
public function SettingsOptionController()
{
super();
TweenPlugin.activate([ShortRotationPlugin, TransformAroundPointPlugin, TransformAroundCenterPlugin, AutoAlphaPlugin]);
this.addEventListener(Event.ADDED_TO_STAGE, initSettingsOptions,false,0,false);
}
private function initSettingsOptions(event:Event = null):void
{
_scl = new SettingsOption();
_scl.x = PADDING + 10;
_scl.y = stage.stageHeight - _scl.height - PADDING;
_scl.alpha = 0;
_scl.scaleX = _scl.scaleY = .65;
addChild(_scr);
addChild(_scl);
TweenLite.to(_scl,1,{transformAroundCenter:{scaleX:1, scaleY:1}, alpha:1, delay:2, ease:Back.easeOut});
_scl.addEventListener(MouseEvent.CLICK,viewSettingsWindow, false,0,false);
this.removeEventListener(Event.ADDED_TO_STAGE, initSettingsOptions);
}
private function removeSettingsWindow():void
{
_isWinActive = false;
}
private function viewSettingsWindow(event:MouseEvent = null):void
{
_settingsWinController = new SettingsController();
addChild(_settingsWinController);
_settingsWinController.viewSettings();
_isWinActive = true;
}
}
}
And finally the controller for the settings window which contains the movie clips and controls that I need to dispatch certain settings in this case volume:
package com.gamehelp.controllers.windows
{
import com.gamehelp.controllers.ui.DimmerController;
import com.gamehelp.sounds.SoundManager;
import com.gamehelp.windows.Settings;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
public class SettingsController extends MovieClip
{
private var _settings :Settings;
private var _settingsDimmer :DimmerController;
private var _musicSliderHandle :MovieClip;
private var _soundSliderHandle :MovieClip;
private var _soundMask :MovieClip;
private var _soundSliderMask :MovieClip;
private var _boundry :Object = {top:0, bottom:120};
private var _offset :Number = 300;
private static const DURA :Number = .65;
public function SettingsController()
{
TweenPlugin.activate([TransformAroundPointPlugin, ShortRotationPlugin]);
this.addEventListener(Event.ADDED_TO_STAGE,initSettings,false,0,false);
}
private function initSettings(event:Event = null):void
{
_settings = new Settings();
_settings.x = stage.stageWidth/2 - _settings.width/2 -30;
_settings.y = -200;
_settings.alpha = 1;
_settings.rotation = -6;
_settingsDimmer = new DimmerController();
_settingsDimmer.visible = false;
_settingsDimmer.mouseEnabled = false;
_settingsDimmer.mouseChildren = false;
addChild(_settingsDimmer);
addChild(_settings);
// set slider handles and sound bar mask
_musicSliderHandle = _settings.musicControl.sliderHandle;
_soundMask = _settings.musicControl.soundMask;
_soundSliderHandle = _settings.soundControl.sliderHandle;
_soundSliderMask = _settings.soundControl.soundMask;
this.removeEventListener(Event.ADDED_TO_STAGE,initSettings);
initSettingEvents();
}
private function initSettingEvents():void
{
_musicSliderHandle.buttonMode = true;
_musicSliderHandle.addEventListener(MouseEvent.MOUSE_DOWN, sliderDown);
this.addEventListener(MouseEvent.MOUSE_UP, sliderUp);
}
private function sliderDown(event:MouseEvent):void
{
this.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
private function sliderUp(event:MouseEvent):void
{
this.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
// this is where I will update the volume
private function onMove(event:MouseEvent):void {
_musicSliderHandle.y = mouseY - _offset;
_soundMask.y = _musicSliderHandle.y + _musicSliderHandle.height/2;
if(_musicSliderHandle.y <= _boundry.top)
{
_musicSliderHandle.y = _boundry.top;
_soundMask.y = _boundry.top + _musicSliderHandle.height/2;
}
else if(_musicSliderHandle.y >= _boundry.bottom)
{
_musicSliderHandle.y = _boundry.bottom;
_soundMask.y = _boundry.bottom + _musicSliderHandle.height/2;
}
event.updateAfterEvent();
}
public function viewSettings():void
{
TweenLite.to(_settingsDimmer, DURA, {autoAlpha:.75});
}
public function closeSettings(event:MouseEvent = null):void
{
TweenLite.to(_settingsDimmer, DURA, {autoAlpha:0});
TweenLite.to(_settings, .75, {transformAroundPoint:{point:new Point(500,-40), rotation:0 }, y:-700, alpha:1});
}
}
}