3 Replies Latest reply on Aug 13, 2013 10:24 AM by Endoplasmic

    Call a function

    Ahoo110@gmail.com

      I am setting this function in my compositionready and I want to call it from different places. That works fine but I also want to run myFunction() when the program launches. So I have this: (and it is not working) what am I doing wrong?

       

       

       

       

      sym.getComposition().getStage().myFunction();

       

       

      sym.myFunction = function()

      {

      alert("function called")

      }

        • 1. Re: Call a function
          resdesign Adobe Community Professional & MVP

          Could you try this:

           

          function myFunction()

          {

          alert("function called")

          }

           

           

          In composition ready:

           

          function myFunction(){

          alert('this button uses myFunction');

          }

           

           

          sym.$('Rectangle').click(function(){

          myFunction();

          });

          1 person found this helpful
          • 2. Re: Call a function
            Ahoo110@gmail.com Level 1

            No it didn't work

             

            I get error if I don't setup the function like

             

            myFunction = function()

            {

            alert("function called")

            }

             

             

            and since I want to call it from different symbols, then I add a sym. to it.

             

            How ever I can't call the function for some reason. I don't know what I am doing wrong.

            • 3. Re: Call a function
              Endoplasmic

              Welcome to the wonderful world of creationComplete being fired before compositionReady!

               

              Here is what I do:

               

              On your "Stage" in compositionReady  you have:

               

              sym.myFunction = function() {

                alert("function called");

              }

               

              //this is where you want to look through the symbols on the stage and fire an onInit function if it's there

              var elements = sym.getChildSymbols();

              var total = elements.length;

              var i = 0;

              for(i; i < total; i++){

                if(typeof elements[i].onInit == 'function'){

                  elements[i].onInit();

                }

              }

               

               

              On your other symbol's creationComplete you have:

               

              sym.onInit = function() {

                sym.getComposition().getStage().myFunction();

              }

               

               

               

              The other option (which I'm just speculating) is to put your function in the creationComplete handler on the Stage object (that *should* get built first). I don't do that myself, but it's possible that it might just work!