Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

There are several questions about learning H5 code

Enthusiast ,
Jul 27, 2018 Jul 27, 2018

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.

669
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 30, 2018 Jul 30, 2018

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));

}

Translate
Community Expert ,
Jul 28, 2018 Jul 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 29, 2018 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 29, 2018 Jul 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);};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 29, 2018 Jul 29, 2018

What is IMO?

I want to add the event inside the code.

Then point to it with the movie clip.

But it always fails.

I want to know the right way to use ANCC.

var Cat = {
    createNew: function(){
      var cat = {};
     cat.pd=this.on("click", function(){alert("Meow")}); 
      return cat;

    }
  };

var cat1=this.cat1

var cat1 = Cat.createNew();

cat1.pd();

var Cat = {
    createNew: function(){
      var cat = {};
     this.on("click", function(){alert("ss")}); 
      return cat;

    }
  };

var cat1=this.cat1
var cat1 = Cat.createNew();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 29, 2018 Jul 29, 2018

imo=in my opinion.

i don't know what you're trying to do or show in msg 5.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 29, 2018 Jul 29, 2018

Don't know why, my forum email reminder disappears.

So it's a lot slower to respond.

What I want to achieve is that there is a click event inside a block of code.

What I want to implement is that there is a click event inside the code block. And the rules of judgment.

I call this code block directly with the movie clips when I need to use it.

There are a lot of movie clips.

They all use this code block.

Automatically judge a different event according to the name of the movie clip

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2018 Jul 30, 2018

use:

var Cat = {

    createNew: function(s){

      var cat = {};

      cat.name = s;

      cat.makeSound = function(){

switch (s){

case 's1':

alert('x');

break;

case 's2':

alert('y');

break;

}

};

      return cat;

    }

  };

var cat1 = Cat.createNew('s1');

cat1.makeSound();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 30, 2018 Jul 30, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2018 Jul 30, 2018

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));

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 30, 2018 Jul 30, 2018

Thank you so much.

I may still need to understand a lot of things.

I'll look at the usage of the mock class again.

Might be better suited to the object method than the mock class

Actually, I was trying to understand what a mock class could do..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2018 Jul 30, 2018
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 28, 2018 Jul 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines