3 Replies Latest reply on Apr 10, 2015 7:23 AM by resdesign

    What is the snippet for a symbol's XY position?

    LabJack

      I am animating a drag drop game and when all 4 pieces are in the right locations, I need another action to happen.

       

      But what is the code for the location of a symbol?

       

      I know it's not getPosition (as that relates to the timeline), and if you put in .css({"position": "absolute", "left": "Xpx", "top": "Ypx"}) then it positions the different symbols top begin with... but still doesn't start the consequent action.

       

      Anyone know?

       

      Here is the code I am using currently:

       

      if(

          (sym.$("Slide").css({"position": "absolute", "left": "45px", "top": "117px"})),

          (sym.$("Rightleg").css({"position":"absolute", "left": "260px", "top": "21px"})),

          (sym.$("Leftleg").css({"position":"absolute", "left": "105px", "top": "30px"})),

          (sym.$("Ladder").css({"position": "absolute", "left": "360px", "top": "16px"}))

          ){

             alert("correct");

      }

        • 1. Re: What is the snippet for a symbol's XY position?
          resdesign Adobe Community Professional & MVP

          There are several ways to find the position of an object.

          • with top() and left()

              var symTop = sym.$('Rectangle').css('top');

              var symLeft = sym.$('Rectangle').css('left');

          • with offset()

              var x = sym.$("elementName").offset();

              alert("Top: " + x.top + " Left: " + x.left);

              Note: you will need jquery

          • with position()

              var position = sym.$("Rectangle").position();

              console.log( "x or left: " + position.left + ", y or top: " + position.top );

                    or

              var x = sym.$("Rectangle").position().left;

              var y = sym.$("Rectangle").position().top;

          • 2. Re: What is the snippet for a symbol's XY position?
            LabJack Level 1

            Thanks resdesign...

             

            Sorry, but would you be able to clarify what those functions above are doing?

             

            From what I can see, they are just placing the symbol.

             

            I already have the symbol moving, but need to phrase a snippet that says - if sym.$("Slide") reaches position XY, AND sym.$("Ladder") reaches position AB, then execute command (in this case, alert "correct")

            • 3. Re: What is the snippet for a symbol's XY position?
              resdesign Adobe Community Professional & MVP

              Maybe something like this? You find the position of each element and if these positions are these numbers you get the alert.

               

              sym.$("Slide").css({"position": "absolute"});

              sym.$("Rightleg").css({"position":"absolute"});

              sym.$("Leftleg").css({"position":"absolute"});

              sym.$("Ladder").css({"position": "absolute"});

               

              // get the position of each element

              var slidePos = sym.$("Slide").offset();

              var RLPos = sym.$("Rightleg").offset();

              var LLPos = sym.$("Leftleg").offset();

              var LPos = sym.$("Ladder").offset()

              // set the conditional for the alert

              if (slidePos.left() == 45 && slidePos.top == 117 && RLPos.left == 260 && RLPos.top == 21 && LLPos.left == 105 && LLPos.top == 30 && LPos.left == 360 && LPos.top == 16){

                alert("correct");

              }