Skip to main content
chenjil43641795
Legend
July 28, 2018
Answered

There are several questions about learning H5 code

  • July 28, 2018
  • 2 replies
  • 769 views

First of all, please forgive me, this H5 novice asks these basic questions.

Question 1:

When I touch and drag, I need to jump to the next frame.

I use "prevframe ();" It's not valid.

So I used the

var js=0;

js=js+1

exportRoot.gotoAndStop(js)

Is "prevframe ()" Not available in H5?

What other common AS3 code is not available?

Question 2:

Formerly used

"function name() {  } "

But now I see a lot of code is

"this.name = function(){}"

What is the principle of this code?

How to use it?

Question 3:

About binding interpretation.

are usually joined".bind (This)."

I'm in a non-native English speaking country.

May translate the reason, the material appears the meaning is very vague.

There is little information and explanations.

In the ANCC "bundle" the usage and the function, hoped can use the popular words to explain

Question 4:

There's one more question.

ANCC H5 How to write a class.

For example, write a class, and then several movie clips bind such a class.

    This topic has been closed for replies.
    Correct answer kglad

    A little bit different.

    In the Var cat i want to add button events.

    button does not specify an instance name.

    var cat1 is the instance name of a movie clip.

    cat1-100, 100 movie clips.

    Each movie clip as long as = Cat.createnew ();

    can be clicked and the event is triggered according to the movie clip instance name.

    The event and trigger code are all inside the Var cat


    that doesn't sound like you want a class-like set-up:

    function addClickF(mc,scope){

    scope.f=function(e){

    if(e.currentTarget.name==whatever){

    // this is a reference to scope

    }

    }

    mc.addEventListener('click',scope.f.bind(scope));

    }

    2 replies

    Legend
    July 28, 2018

    The language is called JavaScript, not "H5". The only H5 is the HTML level 5 heading tag.

    In HTML5 Canvas mode, Animate uses JavaScript and the CreateJS API for graphics and sound.

    https://createjs.com/

    Here is an overview of differences between ActionScript code and HTML5 Canvas code:

    Convert your ActionScript code to HTML5

    prevFrame() in Canvas is just this.gotoAndStop(this.currentFrame - 1).

    kglad
    Community Expert
    Community Expert
    July 28, 2018

    prevframe() (and prevFrame() ) are not valid javascript.

    use whatevertimeline.currenFrame-1

    the first is a named function and the second an anonymous function.  google it to see the differences.

    it's never bind(This), but rather bind(this).  ie, case-counts.  (see line 1, too.)

    scope is lost in canvas/html5 when using named functions.  binding surmounts this.  google function scope to learn more.

    google javascript and class but ancc and class definitions don't work the way they worked in as3.  so, i've not seen anyone make much use of them (in html5/canvas).

    chenjil43641795
    Legend
    July 29, 2018

    Thank you very much for your answer,123 I get it.

    But

    About classes,

    I saw someone say can simulate class.

    For example:

    var Cat = {

        createNew: function(){

          var cat = {};

          cat.name = "Tom";

          cat.makeSound = function(){ alert("Meow"); };

          return cat;

        }

      };

    var cat1 = Cat.createNew();

    cat1.makeSound();

    The code like this.

    Whether this is a class.

    I want to use this as a drag-and-drop pairing.(The drag-and-drop pairing has been completed, just to learn the questions)

    Press and click on the judgment are done in Var.

    Then I put the movie clip equal to. CreateNew ();

    And then it just failed.

    I want to ask if my idea is workable.

    kglad
    Community Expert
    Community Expert
    July 29, 2018

    it works like a class.  whether you call it a class or not is more philosophical than logical.

    the code you showed should work and (imo) would be a better demonstration with:

    cat.makeSound=function(){alert(this.name);};