Skip to main content
The Artworker
Known Participant
October 29, 2018
Answered

JavaScript equivalent of "onEnterFrame"

  • October 29, 2018
  • 3 replies
  • 5796 views

I am repurposing an old Flash AS2 project which now needs to run as an HMTL5 one.

My main function entirely revolves around the AS2 "onEnterFrame" command. There doesn't seem to be an equivalent in JavaScript. How do I trigger a function in the same way?

This topic has been closed for replies.
Correct answer JoãoCésar17023019

I don't think so.

I'm trying to convert my AS2 bit by bit so I can see what works and what doesn't.

At the moment I am falling at the very first hurdle.

I have this very simple function which is supposed to look at the contents of an Text Input Component (called pets_txt) and if it is blank, insert a "0". And if there is something in the field it passes it to a variable called "pets".

if (this.pets_txt.text == "") {

  pets = 0;

  } else {

  pets = this.pets_txt.text;

}

The biggest problem I have is that firstly my AS2 is very rusty - haven't used it for about 5 years, and I simply don't understand most of the JavaScript I'm being offered. I was told that if I understood AS2 I would find JavaScript easy, but I simply not finding that to be the case.

In your example above why is there an "e" in brackets in line 01?

And what does this statement ("tick", tickHandler) in line 06 actually mean/do?


Thanks.

One first thing to understand is that in HTML5 documents, Animate CC outputs compliant content for web standards. So ANCC is limited to what browsers can run and to the way things must work in the web.

The code you write in Animate CC you'll end up in a regular JavaScript file that will be loaded in a regular HTML file.

This means that you can access all DOM related stuff or use any library of your choice.

JavaScript and ActionScript are indeed similar. What can cause confusion is that Animate CC is integrated with a suit of libraries called CreateJS. It means that you have to understand not only the ANCC way of creating and handling graphics, sounds and animations, but you also have to understand the way ANCC targets these things using CreateJS.

Take for example ReactJS: it's a JavaScript library but it takes much more to use it than knowing only vanilla JavaScript.

About the code, what you have to know is that components in AnimateCC are not canvas objects. They are DOM objects attached to a div element called "dom_overlay_container" and by default they are targeted using jQuery.

So my suggestion is:

var pets;

function tickHandler(e)

{

     var textValue = $("#inputText").val();

     if (textValue == "")

          pets = 0;

     else

          pets = textValue;

}

createjs.Ticker.on("tick", tickHandler);

Don't forget to use the Code Snippets panel to learn how to communicate with components.

And to better understand event handlers and listeners, take a look at these two references:

JavaScript DOM EventListener

https://createjs.com/docs/easeljs/classes/Event.html

I hope this helps.

Regards,

JC

3 replies

marliton
Community Expert
Community Expert
October 29, 2018
Marlon Ceballos
Legend
October 29, 2018

Additional discussion on doing this sort of thing here:

Re: Accessing movieClip.children array Animate CC Canvas

JoãoCésar17023019
Community Expert
Community Expert
October 29, 2018

Hi.

Use:

function tickHandler(e)

{

    // your loop code here

}

createjs.Ticker.on("tick", tickHandler);

Regards,

JC

The Artworker
Known Participant
October 29, 2018

Thanks.

However it's not working for me with even a very simple function inside the "tickHandler".

Am I supposed to be changing any of the code other than dropping my loop code where it says?

JoãoCésar17023019
Community Expert
Community Expert
October 29, 2018

Are you trying to use raw AS2 code?

Can you show us your code?