4 Replies Latest reply on Jul 10, 2013 11:38 AM by Endoplasmic

    Calling function outside of stage scope

    John Hall Level 4

      So that it will be easy for me to call a hideNav() function, I put the function outside the stage scope. You can see the end of the stage closure below followed by the various things I've tried that do not work. Suggestions welcomed. The alert fires fine so it's an issue with addressing the back button on the main timeline.

       

       

           .... stage script stuff here

       

        })("stage");

         //Edge symbol end:'stage'

       

      // If you don't understand a concept, put all the words you know in random order and see if something happens  - but it doesn't

       

        function hideNav(){

          alert("hide");

          sym.getComposition().getStage().getSymbol("back").hide();

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

          sym.$("stage").backButton.hide();

          sym.getSymbol("back").hide();

          sym.getParentSymbol().getSymbol("back").hide();

          backButton.hide();

          sym.$("back").hide();

      }

       

      PS, yes I tried them one at a time. This is just a compilation of my greatest non-hits.

        • 1. Re: Calling function outside of stage scope
          Endoplasmic Level 2

          Here is an example using the stage to call the "back" symbol as well as another symbol calling the "back" symbol:

           

          //Edge symbol: 'stage'

          (function(symbolName) {

           

           

            Symbol.bindElementAction(compId, symbolName, "document", "compositionReady", function(sym, e) {

              //if you want a shortcut method

              sym.hideNav = function(){

                sym.getSymbol("back").hideNav();

              }

            });

            //Edge binding end 

          })("stage");

          //Edge symbol end:'stage'

           

           

          //=========================================================

           

           

          //Edge symbol: 'back'

          (function(symbolName) {

           

           

            Symbol.bindSymbolAction(compId, symbolName, "creationComplete", function(sym, e) {

              sym.showNav = function() {

                //do stuff

                console.log('showing');

              }

           

           

              sym.hideNav = function() {

                //do stuff

                console.log('hiding');

              }

            });

            //Edge binding end 

          })("back");

          //Edge symbol end:'back'

           

           

          //=========================================================

           

           

          //Edge symbol: 'something_else'

          (function(symbolName) {

           

           

            Symbol.bindSymbolAction(compId, symbolName, "creationComplete", function(sym, e) {

              //this is an example of another symbol using either method to talk to "back"

              var stage = sym.getComposition().getStage();

           

           

              //method 1 (calls the method on the stage, which calls the method on the symbol)

              stage.hideNav();

           

           

              //method 2 (calls the method on the symbol directly)

              stage.getSymbol('back').hideNav();

            });

            //Edge binding end 

          })("something_else");

          //Edge symbol end:'something_else'

          • 2. Re: Calling function outside of stage scope
            John Hall Level 4

            Thanks much. I will work through this in the morning. I appreciate your time. Looks very promising!

            • 3. Re: Calling function outside of stage scope
              John Hall Level 4

              Well, i created other problems but your hint solved that one. Thank you very much.

              • 4. Re: Calling function outside of stage scope
                Endoplasmic Level 2

                Glad I could help!

                 

                Basically you could say sym.whateverMethod = function(){} or this.whateverMethod = function(){} (both are the same) and then those symbols (when accessed via getSymbol) have public methods that other symbols can access.