10 Replies Latest reply on Jul 22, 2013 11:07 AM by AMULI

    if function doesn´t work

    mr.monsen

      he i´m building a litte animation with 3 pictures. i want to get the picture getting change the positin by clicking and change it back by clicking again or clicking on an other picture.

       

      i put some labels and triggers in my timeline to do that and wrote an if function but it doesn´t work. if i test it, it is jumping from label to label but not the way it should jump

       

      my code is:( it is the code of one picture, the other codes are similary)

       

      if (sym.getPosition () == "e1","e3","e5"){

      sym.play("l2")

      }

      if (sym.getPosition () == "e4","e6"){

      sym.play("l5")

      }

      if (sym.getPosition () == "e2"){

      sym.play("l3")

      }

      else sym.stop()

       

      i also tried it with an else if in the function but it didn´t work. i´m totaly new to html and coding so it would be nice if some can help me.

        • 1. Re: if function doesn´t work
          resdesign Adobe Community Professional & MVP

          At first sight, I would use the || (or) format instead. Let me know if that helps.

          sym.getPosition () == "e1" || sym.getPosition () == "e3" ||sym.getPosition () ==  "e5"

           

          But getPosition returns seconds, not labels.

          Below is a way I used getPosition() on a click event.

           

          var timelinePos = sym.getPosition();

          sym.play(timelinePos);

           

          Sample:

          https://app.box.com/s/oz38265pxejibdhgztux

          • 2. Re: if function doesn´t work
            AMULI Level 4

            Hi Mr Monsen,

             

            1) When you want to test the different possible values for an expression, a much more concise way is the switch conditional statement, where the given expression is written only once. Suppose e1=100 ms, e2=200 ms, etc :

             

            switch( sym.getPosition())

            {

               case 100: case 300: case 500:

                  sym.play('l2');

                  break;

               case 400: case 600:

                  sym.play('l5');

                  break;

               case 200:

                  sym.play('l3');

                  break;

            }

             

            The flow for a switch  : the statements following the first case matching value are executed and a break exits from the switch bloc {} (if you forget the break, then execution continues with the statements for the next cases, which usually is nonsense).

             

            Notice you can factorize the different cases that lead to the same statement(s).

             

            2) If you repeat the same processing on every trigger, you should factorize the code in a function. A good place for it is the Stage.compositionReady event handler:

             

            function updateStage()

            {

                 switch( sym.getPosition())

                 {

                     case 100: case 300: case 500:

                     // etc.

                 }

            }


            Then each trigger reduces to the function call : updateStage();


            It's not only shorter code, but safer code : if the switch is to be evolved, there is only one place to modify (with duplicated code, the risk is that the "duplicatas" end up different !).

             

            Gil

            1 person found this helpful
            • 3. Re: if function doesn´t work
              mr.monsen Level 1

              sadly it doesn´t work. he just keeps playing the wrong stuff. i changed the labels to the timecode but it just didn´t work.

              but thanks for your help

              • 4. Re: if function doesn´t work
                resdesign Adobe Community Professional & MVP

                Are you refering to a symbol or the main timeline? Gil's code should work.

                • 5. Re: if function doesn´t work
                  mr.monsen Level 1

                  i´m refering to the main timeline. i tried gil´s code but edge animate tells me there where some errors so i changed it. but it doesn´t work. i´m still trying to get it work. at the moment my code (for one of the 3 pictures) looks like that:

                   

                  switch (sym.getPosition())

                  {

                  case "2000":

                  sym.play("3000");

                  break;

                  case "0500":

                  sym.play("12000");

                  break;

                  case "6000":

                  sym.play("7000");

                  break;

                  case "12000":

                  sym.play("7000");

                  break;

                  }

                  • 6. Re: if function doesn´t work
                    mr.monsen Level 1

                    i also tried it this way

                    {

                    case 2000:

                    sym.play(3000);

                    break;

                    case 0500:

                    sym.play(12000);

                    break;

                    case 6000:

                    sym.play(7000);

                    break;

                    case 12000:

                    sym.play(7000);

                    break;

                    }

                    • 7. Re: if function doesn´t work
                      AMULI Level 4

                      This one is correct : you test a Number value 6000, not a String value "6000".

                       

                      This is a correct syntax, but may be not the correct logic ! You should give a precise description of what behavior you're trying to program. Then I could post an example to point you in the right direction

                       

                      Gil

                      1 person found this helpful
                      • 8. Re: if function doesn´t work
                        AMULI Level 4

                        As far as I can understand with the sole first sentence of your initial post (which is too vague), the problem submitted in the following thread looks neighbor to yours :

                         

                        http://forums.adobe.com/message/5410456#5410456

                         

                        And you'll find there an example to download. May it inspire you

                         

                        Gil

                        1 person found this helpful
                        • 9. Re: if function doesn´t work
                          mr.monsen Level 1

                          thanks for your help i finally get it done.

                          • 10. Re: if function doesn´t work
                            AMULI Level 4

                            My joy Thanks for your gratitude.

                             

                            Gil