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