4 Replies Latest reply on May 1, 2013 5:55 PM by TimJaramillo

    Setting a variable that I can call it's value from any symbol.

    truth3

      Hey everyone!

       

      I'm working on an edge animate game and I'm learning as I go you can say

       

      The way I have it set up is I have a container that holds different symbols depending on which button you click on. They symbols open you up to a deeper part of the game.

       

      However I want to be able to set a variable on the stage that I can later manipulate when the different symbols are open.

       

      What I have so far is my limited understaning of jquery, in the stage I start off by setting a variable

       

      var variable1 =     5,
          variable2
      =     10;

       

       

      Then in my symbol I want to be able to do something like this


      if(variable1 > variable2) {

       

      Then do something


      }
      else {

       

      Then do something else
      }

      }

       

      variable1 = 10

      variable2 = 5

       

      However the problem I am having is that when I set the variable value in the stage the entire variable name and value is not rememembered in the symbols.

       

      So is there any code I could write in the symbols that can call the variables defined in the stage into the symbols.

       

      Thank you so much for any help. It is greatly appreciated .

        • 1. Re: Setting a variable that I can call it's value from any symbol.
          ray_silvasol

          Hi, I've literally just solved this problem for myself! I've been unable to get variables remembered within symbols too. This will be familiar if you've accessed the Stage from within a symbol already, like so (this kind-of takes a step back and takes you to the main stage from within the symbol):

           

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

           

           

          The way I've updated the score (displayed on the stage) from within a symbol it is to GET the variable from the stage:

           

          var score = sym.getComposition().getStage().getVariable("score");

          score += 100;

          sym.getComposition().getStage().$("valueDisplay").html(score);

          sym.getComposition().getStage().setVariable("score", score);

           

           

           

          So for you I'd recommend:

           

          var variable1 = sym.getComposition().getStage().getVariable("variable1");

          var variable2 = sym.getComposition().getStage().getVariable("variable");

          if(variable1 > variable2) { this }

          else { that }

           

          If you wanted to update the variables and store them on the stage, then you'd do that similarly:

           

          variable1++;

          sym.getComposition().getStage().setVariable("variable1", variable1")

           

           

           

          Hope this helps, I may not be 100% and it may be explained better as I'm learning as I go myself!

          Ray

          • 2. Re: Setting a variable that I can call it's value from any symbol.
            resdesign Adobe Community Professional & MVP

            Glad that you found your answer and shared it. This could be helpful to others.

            • 3. Re: Setting a variable that I can call it's value from any symbol.
              truth3 Level 1

              Thank you so much ray_silvasol! This works perfectly at least from what I see so far. Glad you found a solution to this problem!

              • 4. Re: Setting a variable that I can call it's value from any symbol.
                TimJaramillo Level 4

                You can also do this (this is a little more straightforward than getVariable/setVariable):

                 

                Keep all variable symbols at Stage.compositionReady, and prefix with "sym":

                sym.myVariable = 1;

                 

                 

                And anywhere in your project, you can access the variable like this:

                sym.getComposition().getStage().myVariable = 2;

                1 person found this helpful