TwelvestoneFlash

kill me now


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
DontBogartMe
 
2010-07-29

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

Storm
 
2010-07-29
  • hugs and gropes DBM *
DontBogartMe
 
2010-07-29
  • puts out *
lithium
 
2010-07-29

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.

DontBogartMe
 
2010-07-30

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.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

kill me now