5 Replies Latest reply on Jul 3, 2016 1:13 PM by ericg92808482

    Flash CC: use jQuery functions

    Rotem R

      I want to use jquery functions into flash for html5 game I am building. What I tried to do is add the following lines, and then use simple jquery function, but it seems not loaded, because I get the error: $ is not defined


      My code, which is in the first frame of the main timeline, is:

      var head = document.getElementsByTagName('head')[0];
      var file = "http://code.jquery.com/jquery-1.11.0.min.js";
      var ref = document.getElementsByTagName('script')[0];
      var js = document.createElement('script');
      js.src = file;
      ref.parentNode.insertBefore(js, ref);


      The result I see in the console log, is the following:

            <meta charset="UTF-8">
            <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script src="http://code.createjs.com/easeljs-0.7.1.min.js"></script>
           <script src="http://code.createjs.com/tweenjs-0.5.1.min.js"></script>
           <script src="http://code.createjs.com/movieclip-0.7.1.min.js"></script>
           <script src="ggg.js"></script>
           <script> var canvas, stage, exportRoot;
                function init()
                     canvas = document.getElementById("canvas");
                     exportRoot = new lib.ggg();
                     stage = new createjs.Stage(canvas);
                     stage.addChild(exportRoot); stage.update();
                     createjs.Ticker.addEventListener("tick", stage);
           </script> </head> ggg.js:163



      1. > Uncaught ReferenceError: $ is not defined


      What is wrong with that? and what I have to do so I can use jquery?



        • 1. Re: Flash CC: use jQuery functions
          moccamaximum Level 5

          where do you define the Dollar var of this line:


          console.log($(document).height()); ?

          • 2. Re: Flash CC: use jQuery functions
            Rotem R Level 1

            As shown in line 9 of the code above, I wrote: console.log ($ (document) .height ());

            I did not think, I needed to set the variable $, because jquery is already doing it. Is not it?


            If I try to write the line: <script src = "http://code.jquery.com/jquery-1.11.0.min.js"> </ script> within the <head> html file manually, then there is no problem and I get the height of the screen, even without defining the variable $.

            Which brings me to the conclusion that, although the line was written in the file, as you can see in the console log, but it still does not start ...


            The problem is, if I write the line in the html file manually, when I do publish .fla file, Flash CC erases the line and everything was written by hand. So I thought to write the above code from the first frame of the timeline.


            Is there a better way?

            And yet - why the above code tweaks error message?



            • 3. Re: Flash CC: use jQuery functions
              Nipun Asthana Adobe Employee

              Hi Rotem,


              The correct way would be to publish your canvas project once, then open the published html externally and include the jquery lib or any other lib you may want to use.

              Now go back to the fla file in Flash Pro, open Publish Settings and uncheck - 'Overwrite HTML' option.

              This way, your HTML file does not get overwritten everytime you publish and only the drawing assets and animation gets updated.


              PS: This setting was made available in the last release: Flash Pro CC 2014 ( So make sure to update your Flash Pro if it is not up to date.



              1 person found this helpful
              • 4. Re: Flash CC: use jQuery functions
                Rotem R Level 1

                Oh, that's a great idea! Thank you!

                • 5. Re: Flash CC: use jQuery functions
                  ericg92808482 Level 1

                  I am wondering about the same thing. Is this still the proper way to do it using Animate CC? I'm asking because this post is now 2 years old...not sure if anything was changed.