2 Replies Latest reply on Jul 23, 2013 8:20 AM by resdesign

    Communication between Symbols/Elements

    ThePixell95

      Hey Guys,

       

      I have a very basic question.

      I have a Textfield where you can put a number in.

       

      I also have another symbol where I want to "import" this number.

      The question is, how can I get the variable with the number from the one symbol to the other?

       

      I dont really found an answer in the documentation or something.

       

      Cheers

      - Daniel

        • 1. Re: Communication between Symbols/Elements
          resdesign Adobe Community Professional & MVP

          I suppose there are multiple ways to do this. Depends exactly what you are doing.

           

          // 2 variables that you compare when needed. They would not have to be the same all the time. Only when you decide it.

          var myNumber = 20;

          //Then you can use the variable in textField and change it.

          sym.$('textField').html(myNumber);

          // assign variable to the text Text in the symbol otherfield

          myOtherNumber = myNumber;

          sym.getSymbol('otherfield').$('Text').html(myOtherNumber);

           

          // you can use the same variable and when it changes in the first field it will also change in the other one since it is the same variable.

          var myNumber = 20;

          sym.$('textField').html(myNumber);

           

          // it will have the same value as the first one.

          sym.getSymbol('otherfield').$('Text').html(myNumber);

           

           

          here is a comparison on a click event:

           

          // assign variables for each text field.

          var myNumber = 25;

          var myOtherNumber = 12;

           

          sym.$('textField').html(myNumber);

          sym.getSymbol('otherfield').$('Text').html(myOtherNumber);

           

           

          // click event compare the 2 variables and fills in the text field.

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

           

          if (myOtherNumber == myNumber){

          sym.getSymbol('otherfield').$('Text').html(myOtherNumber);

          }

          else{

          sym.getSymbol('otherfield').$('Text').html('sorry');

          }

           

           

          });

          1 person found this helpful
          • 2. Re: Communication between Symbols/Elements
            resdesign Adobe Community Professional & MVP

            If you have an input field then you can get the value then you could do it this way:

             

            var textField2= sym.$("textField2");

            textField2.html("Enter your number ");

            myNumber = $('<input />').attr({'type':'text', 'value':'', 'id':'textField2'});

            myNumber.css({'font-size': 14, 'background-color': '#0a81fb','box-shadow': '#0a81fb','width': 250});

            myNumber.appendTo(textField2);

             

             

            var otherField2 = sym.getSymbol('otherfield2').$('Text');

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

            var newValue = myNumber.attr("value");

            otherField2.html(newValue);

            });

             

             

            Here is the file with both examples:

             

            https://app.box.com/s/9jq27re2w0todtbjhur7