5 Replies Latest reply on Jun 26, 2012 8:43 AM by tidamz22

    AS3 and Javascript

    A.kameshwaran

      Hi,

       

           I would like to know, how can i write the javascript function for the below code inside /* js */ in the timeline.

       

      ball_mc.buttonMode =true;

      ball_mc.addEventListener(MouseEvent.CLICK,click_on_ball);

       

      function click_on_ball(e:MouseEvent):void

      {

          alert("Clicked")

      }

       

       

      When i publish, swf is working fine. But, when i export for html5 it is not working.

       

      Regards,

      Kameshwaran A.

        • 1. Re: AS3 and Javascript
          Ned Murphy Adobe Community Professional & MVP

          Look into using the ExternalInterface class.  Search Google for a tutorial using terms like "AS3 ExternalInterface tutorial"

          • 2. Re: AS3 and Javascript
            A.kameshwaran Level 1

            Thanks for the response. If i used external interface class, is it possible for me to play with the timeline. Because, onclick of the ball i have a timeline animation in which the ball will speak and jump.

             

            var ballCount:Number = 0;

            function click_on_ball(e:MouseEvent):void

            {

                    if (ballCount < 3)

                    {

                        ballCount++;

                        var level = "click" + ballCount;

                        ball_mc.gotoAndPlay(level);

                    }

            }

            • 3. Re: AS3 and Javascript
              Ned Murphy Adobe Community Professional & MVP

              You can have Actionscript  talking to javascript functions and javascript talking to Actionscript functions, so as long as you can deal with your animation controls via functions you should be good.

              • 4. Re: AS3 and Javascript
                A.kameshwaran Level 1

                Animation and controls are working fine except if i export using createJS, animation and controls are not working.

                 

                when i check the have mentioned in the adobe site like below,

                 

                 

                Published MovieClip symbols expose methods to control the timeline, similar to ActionScript.

                 

                mc.gotoAndPlay("animateOut");
                mc.gotoAndStop(10);
                mc.stop();
                mc.play();

                 

                 

                 

                JavaScript does not use this as an implicit scope, so you must specify your scope in any timeline scripts. For example:

                 

                /* js

                this.onClick = function() {  

                this.gotoAndPlay(0);

                } */

                 

                Note: Unlike Flash, which starts frame indexes at 1, EaselJS timelines begin at 0. This difference in indexing requires you to subtract 1 from the frame indexes displayed in Flash Professional. For example, gotoAndPlay(0) moves the playhead to the first frame of the movie clip in EaselJS, which is labeled as frame 1 in Flash Pro.

                 

                 

                 

                So i do have a doubt, how i can implement my above as coding in the javascript

                • 5. Re: AS3 and Javascript
                  tidamz22

                  Hello,

                   

                  with this kind of script :

                   

                  /* js

                  this.onClick = function() { 

                  this.gotoAndPlay(0);

                  } */

                   

                   

                  how do you do roll over and roll out effects ?

                   

                  Thanks

                  Tidamz