I placed an html input text element with the tag <input> that collects data entered by the user when the user hits the ‘return’ or the ‘enter’ key. I placed it in the animation div that contains the canvas from Adobe Animate CC. I edited the html file that Adobe Animate generates to add a link for the jQuery library but to do so, I had to disable the overwirte option in the advanced tab of the publish settings. You can insert html elements into the html file using just javascript, but it’s a lot easier with jQuery.
Here is the code I used in the action’s panel actions layer of frame1
this.stop();
$("#canvas").after("<form id='userinput_form' onsubmit='return false'><input id='txtInput' type='text'></form>");
var txtInput = $("#txtInput");
txtInput.css({
"position":"absolute",
"top":"180px",
"left":"200px",
"text-align": "center",
"color": "red",
"fontFamily": "Happy Monkey",
"fontSize": "40px",
"height": "60px",
"width": "100px",
"font-weight": "bold"
});
txtInput.focus();
var mainTL = this;
txtInput.keyup(function(e){
if ( e.which == 13 ){
var userAns = txtInput.val();
mainTL.respondTxt.text = "Your Answer is: " + userAns;
//alert("Your Answer: " + userAns + " is correct!");
}
})
Update 06/02/18:
Since 2017 Adobe has included a feature in the actions panel that actually lets you include external libraries like jQuery. I wasn’t sure how to use it until I watch a video by Joseph Labreque explaining how to use it. Here’s what you have to do. Here are instructions for the CDN
- Go to google https://developers.google.com/speed/libraries/#jquery
- Copy the src of the library you need without the <scrip> tags just: https://developers.google.com/speed/libraries/#jquery
- Open your fla file and open the actions panel
- On the left click on Global>include and + on the top right
- select url and paste the src from Google.
That’s it – you’re ready to add jQuery code.
UPDATE: In the Global tab you can also add your own external JavaScript files that are stored in your computer.