7 Replies Latest reply on Jul 20, 2016 6:49 PM by xu zhang

    how include codes like AS2,make html(canvas) files?

    xu zhang Level 1

      like this:

      as2 can include codes :#include "aaa.as".

      how can i do it in animate cc html(canvas) files?

      I have more than one document, using the same set of code. If you can refer to external code, such easy to modify and use need not duplicated code.

      sorry my english!!!!

      thank you of help!!

        • 1. Re: how include codes like AS2,make html(canvas) files?
          kglad Adobe Community Professional & MVP

          copy and paste the code from aaa.as into the fla actions panel.  then convert that code to easeljs/javascript.

           

          and that's not necessarily easy.

          1 person found this helpful
          • 2. Re: how include codes like AS2,make html(canvas) files?
            xu zhang Level 1

            HI kglad!

            thanks you help! i know convert the code and I have achieved.

            My question is, how to put the code in the external for reference.like as2 the code is "aaa.as".

            how animate cc html5 canvas files include the code as as2 do that "#include aaa.as"?

            • 3. Re: how include codes like AS2,make html(canvas) files?
              kglad Adobe Community Professional & MVP

              the code is in a separate (.js) file after you publish.

              • 4. Re: how include codes like AS2,make html(canvas) files?
                ClayUUID Adobe Community Professional

                The approach I've found to be most robust across various platforms (web, local/network drive, etc) is to use tag loading. In the first frame I'll have something like this:

                 

                this.stop();
                _root = this;
                var script = document.createElement("script");
                script.src = "libs/myjslib.js";
                document.head.appendChild(script);
                

                 

                Then as the last statement of the JS file itself I'll have a _root.play(); to resume the timeline. Note though that during development you'll probably have an issue with the JS file getting cached by Animate's local web server (not using the most recent version), so you can cache-bust by adding some "random" digits to the script source:

                 

                script.src = "libs/myjslib.js?" + new Date().getTime();
                
                2 people found this helpful
                • 5. Re: how include codes like AS2,make html(canvas) files?
                  xu zhang Level 1

                  Hi Clay’s Unique UID!

                  thanks your help! sorry my english(I am improve it)!  you answer is link a JS files.my code like this:

                  animate cc:

                  this.stop()
                  that=this
                  that.backmc.menu_dxly_sub.visible = false
                  that.backmc.menu_dxly.cursor = "auto"
                  that.backmc.menu_home.cursor = "auto"
                  that.backmc.menu_dxly.on("click", function () {
                    that.backmc.menu_dxly_sub.visible = !that.backmc.menu_dxly_sub.visible
                  })
                  that.backmc.menu_home.on("click", function () {
                    getmenu("home")
                  })
                  for (var i = 1; i <= 10; i++) {
                    var mc = that.backmc.menu_dxly_sub["btn" + i]
                    if (!mc) {
                    continue;
                    }
                    mc.thisNum = i
                    mc.cursor = "auto"
                    mc.on("click", function () {
                    getmenu("sub_" + this.thisNum)
                    });
                  }
                  

                   

                  I want to clip the code form number 3 to end.put it a new JS files (I have a lot of documents to reference to it ).

                  I try to use the method of reference JS to implement, but the result is not ideal.

                  Because of "that is not defined".maybe the moveclipe in animate cc files is existence,but JS is no or can't read it.

                  • 6. Re: how include codes like AS2,make html(canvas) files?
                    ClayUUID Adobe Community Professional

                    Put your code in a function. Put the function in the external .js file. Call the function wherever that code used to be.

                     

                    Get rid of "that=this". It won't work because "this" will be the wrong scope. Pass "that" into the function as an argument, so call the function like myFunction(this); Or change all "that"s to "_root" which is already defined by the script loader as pointing to the main timeline. Or change "_root" in the script loader to "that" (not recommended, because "that" is not descriptive).

                    1 person found this helpful
                    • 7. Re: how include codes like AS2,make html(canvas) files?
                      xu zhang Level 1

                      Thank you very much!!

                      Perfect!!