I've just written this
if (this is BtnInGameHelp) {
thisSfxClass = SfxHowToPlay;
thisSfxName = "SfxHowToPlay";
} else if(this is BtnPlayDrivingLevel) {
thisSfxClass = SfxDrive;
thisSfxName = "SfxDrive";
} else if(this is BtnPlayFlyingLevel) {
thisSfxClass = SfxFly;
thisSfxName = "SfxFly";
} else if(this is BtnPlayWalkingLevel) {
thisSfxClass = SfxRun;
thisSfxName = "SfxRun";
} else if(this is BtnSkipVideo) {
thisSfxClass = SfxSkipVideo;
thisSfxName = "SfxSkipVideo";
} else if(this is BtnTurnMusicOff) {
thisSfxClass = SfxSoundOff;
thisSfxName = "SfxSoundOff";
} else if(this is BtnTurnMusicOn) {
thisSfxClass = SfxSoundOn;
thisSfxName = "SfxSoundOn";
} else if(this is BtnRestartCar) {
thisSfxClass = SfxDrive;
thisSfxName = "SfxDrive";
} else if(this is BtnRestartGrandpa) {
thisSfxClass = SfxRun;
thisSfxName = "SfxRun";
} else if(this is BtnRestartPlane) {
thisSfxClass = SfxFly;
thisSfxName = "SfxFly";
} else if(this is BtnCloseHelpCar) {
thisSfxClass = SfxDrive;
thisSfxName = "SfxDrive";
} else if(this is BtnCloseHelpGrandpa) {
thisSfxClass = SfxRun;
thisSfxName = "SfxRun";
} else if(this is BtnCloseHelpPlane) {
thisSfxClass = SfxFly;
thisSfxName = "SfxFly";
} else if(this is BtnPlaySlowCar) {
thisSfxClass = SfxSlow;
thisSfxName = "SfxSlow";
} else if(this is BtnPlaySlowGrandpa) {
thisSfxClass = SfxSlow;
thisSfxName = "SfxSlow";
} else if(this is BtnPlaySlowPlane) {
thisSfxClass = SfxSlow;
thisSfxName = "SfxSlow";
} else if(this is BtnPlayFastCar) {
thisSfxClass = SfxFast;
thisSfxName = "SfxFast";
} else if(this is BtnPlayFastGrandpa) {
thisSfxClass = SfxFast;
thisSfxName = "SfxFast";
} else if(this is BtnPlayFastPlane) {
thisSfxClass = SfxFast;
thisSfxName = "SfxFast";
} else if(this is BtnHowToPlay) {
thisSfxClass = SfxHowToPlay;
thisSfxName = "SfxHowToPlay";
} else if(this is BtnBackToMenu) {
thisSfxClass = SfxChooseAnotherLevel;
thisSfxName = "SfxChooseAnotherLevel";
}
kill me now. My eyes are bleeding.
hugs Storm
- hugs and gropes DBM *
- puts out *
import flash.utils.Dictionary; import flash.utils.getQualifiedClassName;
var classDict : Dictionary = new Dictionary(); classDict [ BtnInGameHelp ] = SfxHowToPlay; classDict [ BtnPlayDrivingLevel ] = SfxDrive; classDict [ BtnPlayFlyingLevel ] = SfxFly; classDict [ BtnPlayWalkingLevel ] = SfxRun; classDict [ BtnSkipVideo ] = SfxSkipVideo; classDict [ BtnTurnMusicOff ] = SfxSoundOff; classDict [ BtnTurnMusicOn ] = SfxSoundOn; classDict [ BtnRestartCar ] = SfxDrive; classDict [ BtnRestartGrandpa ] = SfxRun; classDict [ BtnRestartPlane ] = SfxFly; classDict [ BtnCloseHelpCar ] = SfxDrive; classDict [ BtnCloseHelpGrandpa ] = SfxRun; classDict [ BtnCloseHelpPlane ] = SfxFly; classDict [ BtnPlaySlowCar ] = SfxSlow; classDict [ BtnPlaySlowGrandpa ] = SfxSlow; classDict [ BtnPlaySlowPlane ] = SfxSlow; classDict [ BtnPlayFastCar ] = SfxFast; classDict [ BtnPlayFastGrandpa ] = SfxFast; classDict [ BtnPlayFastPlane ] = SfxFast; classDict [ BtnHowToPlay ] = SfxHowToPlay; classDict [ BtnBackToMenu ] = SfxChooseAnotherLevel;
public function updateSoundFX ( type : Class ) : void { var sfxClass : Class = classDict [ type ] as Class;
if ( sfxClass != null )
{
var type : String = getQualifiedClassName ( sfxClass );
var typeName : String = type.indexOf ( "::" ) > -1 ? type.split ( "::" ).pop() : type;
thisSfxClass = sfxClass;
thisSfxName = typeName;
}
}
Might not be the most elegant solution, but it's a lot easier than adding new conditions each time you add a new sound effect.
usage would be something like
// wherever your large if/else statement was
var thisClass : Class = getDefinitionByName( getQualifiedClassName ( this ) ) as Class; updateSoundFX ( thisClass );
Hope it helps.
A.
yup, that's a lot nicer than mine. I always forget about the Dictionary. Thanks Lith.
I've put mine in now though, and tested it already so it stays as is. Really though... day before launch .... I get the FLA back from my designer/client with a different sound clip put on the over frame of 20-odd buttons, and suddenly the app sounds like shit. And the sound on/off no longer works... hence my emergency dodgy code.
All sorted now, but what a PITA.