6 Replies Latest reply on May 21, 2016 11:08 PM by rahimhaji

    How to track and find which button clicked in Animate CC script.

    rahimhaji Level 1

      Dear Friends,

       

      Iam converting an elearning lessons in Animate CC. I have the following code for an activity like click each buttons and see corresponding popups.

       

      import flash.events.MouseEvent;

      for (var i:Number = 1; i<=5; i++)

      {

      this["btn" + i].addEventListener(MouseEvent.CLICK, btn_clicked);

      }

      function btn_clicked(event:MouseEvent)

      {

      trace(event.target.name.substr(3));

      }

       

      Kindly help me to convert this to java script code in animate CC.

       

      Thanks in Advance,

       

      Syed Abdul Rahim

        • 1. Re: How to track and find which button clicked in Animate CC script.
          rahimhaji Level 1

          Dear Friends,

           

          Iam converting an elearning lessons from Flash AS3 to  Animate CC - JS. I have the following code for an activity like click each buttons and see corresponding popups.

           

          import flash.events.MouseEvent;

          for (var i:Number = 1; i<=5; i++)

          {

          this["btn" + i].addEventListener(MouseEvent.CLICK, btn_clicked);

          }

          function btn_clicked(event:MouseEvent)

          {

          trace(event.target.name.substr(3));

          popup.gotoAndPlay("pg"+event.target.name.substr(3));

          }

           

          it should go to particular popup.

           

          Kindly help me to convert this to java script code in animate CC.

           

          Thanks in Advance,

           

          Syed Abdul Rahim

          • 2. Re: How to track and find which button clicked in Animate CC script.
            rezun8 Level 4

            Syed,

             

            If you use Google DCM to traffic the ads, you can create ID's for each button that will track just this sort of thing.

            Outside of that I cant help you.

            • 3. Re: How to track and find which button clicked in Animate CC script.
              ClayUUID Adobe Community Professional

              Rezun, he clearly said this is for an e-learning product, not a banner ad.

               

              Syed, if you have a button already created on the stage, click the <> symbol in the upper-right of the Actions panel, then select HTML5 Canvas -> Event Handlers -> Mouse Click Event. This will insert the code needed to script buttons in Canvas mode. It looks like this:

               

              /* Mouse Click Event
              Clicking on the specified symbol instance executes a function in which you can add your own custom code.
              
              Instructions:
              1. Add your custom code on a new line after the line that says "// Start your custom code" below.
              The code will execute when the symbol instance is clicked.
              */
              
              this.button_1.addEventListener("click", fl_MouseClickHandler.bind(this));
              
              function fl_MouseClickHandler()
              {
                  // Start your custom code
                  // This example code displays the words "Mouse clicked" in the Output panel.
                  alert("Mouse clicked");
                  // End your custom code
              }
              
              1 person found this helpful
              • 4. Re: How to track and find which button clicked in Animate CC script.
                rahimhaji Level 1

                Dear Mr.Clay,

                 

                Thanks for the reply. Already I did this iam writing code. Now I solved how to track the click button with the following code:

                this.stop();
                var sel_but = "";
                for(inc1=1; inc1<=7;inc1++)
                {
                this["btn_"+inc1].name = "button"+inc1;
                this["btn_"+inc1].addEventListener("click", fl_MouseClickHandler);
                }

                function fl_MouseClickHandler(event)
                {
                sel_but = event.target.name.substr(6);
                alert("Mouse clicked "+ sel_but);
                this["popup"+sel_but)].gotoAndPlay("play_area");
                }

                 

                Here I have assigned name (this["btn_"+inc1].name = "button"+inc1;) for each button my self and tracking with those names. So tracking is solved. But I have to play respective popup movie clips. Now its not working ( this["popup"+sel_but)].gotoAndPlay("play_area"); ). I don't know how to refer my popup mc. I have 7 popup here. Anybody can help me pls.. its urgent...

                 

                Thanks in Advance.

                 

                Regards,

                Syed Abdul Rahim

                • 5. Re: How to track and find which button clicked in Animate CC script.
                  ClayUUID Adobe Community Professional

                  It's not working because you're not using .bind() like in Adobe's sample code, so the event handler is executing in the context of the document window instead of the context it was defined in. Try changing the alert to alert(this) to see what's happening.

                  1 person found this helpful
                  • 6. Re: How to track and find which button clicked in Animate CC script.
                    rahimhaji Level 1

                    hi friends,

                     

                    thks for ur help. I made it work, with the following code:

                     

                    this.stop();
                    var sel_but = "";
                    _this = this;
                    for (inc1 = 1; inc1 <= 7; inc1++) {
                    this["btn_" + inc1].name = "button" + inc1;
                    this["btn_" + inc1].addEventListener("click", fl_MouseClickHandler);
                    }

                    function fl_MouseClickHandler(event) {
                    sel_but = event.target.name.substr(6);
                    _this.popUp.gotoAndPlay('pg'+sel_but);
                    }

                     

                    May be useful to some body...

                     

                    Thanks and Regards,

                    Syed Abdul Rahim