16 Replies Latest reply on Jan 21, 2016 6:56 AM by resdesign

    Storing the value of click into a variable

    baboomsha

      Hi!

       

      Not a very good programmer, I have this project that I'm working on which I'm creating in Edge Animate. Here it goes.

       

      I have a few Labels which act as little clips, for example, 'Clip 01', 'Clip 02', 'Clip 03', 'Clip 04'.

      At the bottom I have something like a menu bar. If I click on 'Clip 01', the Clip corresponding to it plays, like 'Clip 02', 'Clip 03', 'Clip 04' buttons play their respective clips.

      Here's what I want to do instead, If I click on 'Clip 01', the value of the click event which could be 1 for clicked and 0 for not clicked be stored into a variable.

      Before 'Clip 01' actually starts playing, it should check for the value whether it's 1 or 0. If it's 1 then it should play else it should do nothing.

       

      The above is only an example of what I'm trying to create. In other words, if I try and explain what I'm actually to create or where, it would take a really long time to explain hence, the short example above.

       

      Thanks in advance

        • 1. Re: Storing the value of click into a variable
          baboomsha Level 1

          Never mind, I got the answer what I was looking for through the thread mentioned below:

          Re: Problem with "if - else if" statement with mouse click.

           

          What I did was on the click event I initialized the symbol as

          var mySymbolButton = 1;

           

          and then when the clip was about to start i put a check for if and else whether mySymbolButton ==1

          • 2. Re: Storing the value of click into a variable
            resdesign Adobe Community Professional & MVP

            If you have several buttons here are 2 ways to do it:

            If you can use jquery use this group all your buttons in a div and call the group buttons.

            var buttons = sym.$("buttons").children();    

            $.each(buttons,function(i){

              $(this).on("click", function(){

              //code here

              sym.$("images").css({"opacity":0.00});

              sym.$("images").animate({"opacity":1.00},700).attr('src',"images/" + images[i] + ".png");

              });

             

            })

             

             

            If not use this:

             

            function useButtons(element) {

                 sym.$(element).bind("click",function() {

                    // this example changes an image

                   sym.$('image').attr('src','images/'+element+'.png').css({"opacity":1.00});

              });

            }

            // add button names here

            ['', '','' ,'',''].forEach(useButtons);

            • 3. Re: Storing the value of click into a variable
              baboomsha Level 1

              Hey thanx again.

               

              Okay, now for the lengthy explanation in a short way, I am trying to create an entire website in Adobe Egde. I have the sections of pages in different symbols where in I have separate symbols for the buttons. Each section has a home button, and two links that take you to separate sections of the website.

               

              Something like this:

              Home to About Panauti

              Home to Contact Us

              Home to First Floor (Where in another Home icon is there which when clicked plays label called '1stFloortoHome'

              First Floor to 2nd sub section (Where in another Home icon is there which when clicked plays label called 2nd sub section to First floor, but here's the catch, when this part is played, it checks the value whether 1 or 0, if 1 the play head then jumps to label called '1stFloortoHome'


              Similarly there are few more options like these. Now I can complete the entire website. Will post the link when done. Your code was like super simple, super easy, super awesome and using it, I can use a few labels, where i can put the if and else condition to get the desired results.


              You deserve a big applaud. thanx again.

              • 4. Re: Storing the value of click into a variable
                resdesign Adobe Community Professional & MVP

                Wow, you are very welcome! Nice to see someone so enthusiast!

                • 5. Re: Storing the value of click into a variable
                  baboomsha Level 1

                  Another short question,

                   

                  Can i specify multiple if and else conditions one after another something like this:

                  condition 01: if-> do this, else-> do this

                  condition 02: if-> do this, else-> do this

                  condition 03: if-> do this, else-> do this ..... so and so forth

                   

                  or do I need to have something like in one big if and else condition like this:

                  condition 01: if-> do this, else-> do this, (condition 02) else-> do this, (condition 03) else-> do this,..... so on and so forth.

                  • 6. Re: Storing the value of click into a variable
                    resdesign Adobe Community Professional & MVP

                    i would use the switch statement when I have lots of conditionals.

                    • 7. Re: Storing the value of click into a variable
                      baboomsha Level 1

                      thats the link of the project:

                      Traditional Newari-style Guest House in Panauti, Nepal | Matan Chhen

                       

                      You see the links: 'Home Icon' on every section and there are two extra items on every section called 'About Panauti' and 'Contact Us'. Basically all these are in one big symbol of that section, they appear and dissapear. If you click now on the 'Home Icon', it just takes you to prevvious section.

                       

                      Will be working on it today, now that I have the understanding of the code, I would be able to finish the rest. It will go to the previous section, check for the button clicked, then play ahead to previous section before it.

                      • 8. Re: Storing the value of click into a variable
                        baboomsha Level 1

                        Please explain the switch statement, not from programming background.

                        • 9. Re: Storing the value of click into a variable
                          resdesign Adobe Community Professional & MVP

                          Instead of the if else statements you use this syntax. stuff is the variable. When stuff = 0 case 0 is done and so on.

                           

                          switch(stuff) {

                              case 0:

                                  //do something

                                  break;

                              case 1:

                                  //do something
                                  break;

                               case 0:

                                  //do something
                                  break;

                               case 0:

                                  //do something
                                  break;

                              default:

                                  default code block

                          }

                          • 10. Re: Storing the value of click into a variable
                            baboomsha Level 1

                            Okay now, when I put even a simple if and else statement, and even if in the else there is nothing except for stop, when I run it, it just ignores the statement and starts playing from the next label. Very strange.

                            • 11. Re: Storing the value of click into a variable
                              baboomsha Level 1

                              right now this is the code that I have at the end of label part:

                               

                              if (GrndFlrAPLC == 1) {

                              sym.play("Home2Panauti");

                              GrndFlrAPLC = 0;

                              }else{

                              sym.stop();

                              }

                              • 12. Re: Storing the value of click into a variable
                                resdesign Adobe Community Professional & MVP

                                Hey can you PM me a link to your files. that would be easier to see what is going on.

                                Thanks.

                                • 13. Re: Storing the value of click into a variable
                                  baboomsha Level 1

                                  sent. When you receive it, and once you've opened it, lemme know.

                                  • 14. Re: Storing the value of click into a variable
                                    baboomsha Level 1

                                    No issues,

                                     

                                    Here's what I'm trying to do:

                                     

                                    In the project file you would see a symbol called 'GroundFloorTimeline'

                                    In that symbol there is another symbol called 'GFAPLink' which is for the 'About Panauti' link.

                                    Now, whenever I click on that symbol, I want a variable to be created and the value for that variable be set to 1.

                                    On the stage, you would see a label called 'Home2GF' and at the end of that label, it stops.

                                    When it reaches that stop, I want to get the value of variable, the same variable which now has 1 since 'GFAPLink' was clicked. If the value is 1, then it shouldn't stop, it should then go to and play from label called 'Home2Panauti'. Once it executes the play command, the same variable should now have a value of 0, since we want to reset it. In the same if else condition, if the value of the variable is not 1, meaning 'GFAPLink' was not clicked, then it should just stop.

                                     

                                     

                                    P.S: Lemme know whenever you open the files, in your free time. I hope the instructions mentioned are easy to understand, else I'l be explain further.

                                    • 15. Re: Storing the value of click into a variable
                                      baboomsha Level 1

                                      Alright, after getting that small problem resolved yesterday, I ran into the same if and else conditions where in at one stage I had to pur around 6 and then later 9 if and else conditions.

                                       

                                      Tried-> failed, tried-> failed, tried-> failed

                                       

                                      Then came back to your solution again about using switch, had to be very careful with the case conditons, had to rename variables but, it worked out in the end. And it worked out in the first attempt itself and very very smooth.

                                       

                                      The project is almost over, I still need to update some of the images but, that's just simple part. All the difficult part is done. All thanx to you. I really appreciated your help yesterday as well as your switch command. Pure genious. Bravo to you.