2 Replies Latest reply on Apr 25, 2014 2:03 PM by Zaxist

    Pass variables in symbols to function

    nicholaslue

      I'd appreciate some quick help on how to pass a variable I set in a symbol to a function in the compositionReady code. 

       

      Right now for each button in a menu I have the code: 

       

       

      case 'item1':

      sym.getComposition().getStage().clearStage();  //this is a function in compositionReady

      sym.getComposition().getStage().getSymbol("object_details").$("item1").show();

      sym.getComposition().getStage().getSymbol("object_details").getSymbol("item1").play(0);

      break;

       

       

      here is the code in compositionReady:

       

      sym.clearStage = function() {

      sym.getComposition().getStage().$("grid").hide();

      sym.getComposition().getStage().$("othermaps").hide();

      }

       

       

      Is there a way to pass the value 'item1' to the function so that I'm not writing the same code over and over? 

      Thus:

       

      case 'item1':

      sym.getComposition().getStage().clearStage("item1");

      break;

       

       

      and in compositionReady:

       

      sym.clearStage = function(itemValue) {

      sym.getComposition().getStage().$("grid").hide();

      sym.getComposition().getStage().$("othermaps").hide();

      sym.getComposition().getStage().getSymbol("object_details").$(itemValue).show();

      sym.getComposition().getStage().getSymbol("object_details").getSymbol(itemValue).play(0);

      }

       

       

       

      I know my syntax is totally wrong.  Please help me to see this.  Thank you. 

        • 1. Re: Pass variables in symbols to function
          TimJaramillo Level 4

          Your syntax for passing the parameter via the function call, and receiving it in the actual function seems fine.

           

          One note: I'm assuming when copy/pasting youre code for this thread, you left out the 'switch', in your 'switch/case' code? But it's actually there in your code?

          1 person found this helpful
          • 2. Re: Pass variables in symbols to function
            Zaxist Level 4

            this way you can make your codes much shorter :

             

            case 'item1':

            x.clearStage("item1");

            break;

             

            //and in compositionReady:

             

             

            Stage = sym.getComposition().getStage()

             

             

            x = {

             

            clearStage:function(z){

             

            Stage.$("grid").hide();

            Stage.$("othermaps").hide();

            Stage.getSymbol("object_details").$(z).show();

            Stage.getSymbol("object_details").getSymbol(z).play(0);

            }

             

            }

             

             

            regards

            Zaxist

            1 person found this helpful