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

using key presses to call a function

New Here ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

Hi, i am trying to get the "enter" key press to call the same function as my button click for a textinput component in animate (canvas), but it seems to not want to work with anything that uses a "this", only with elements that are actually part of the DOM that are referenced with getElementById.

 

I have this code here for the eventlistener and the function:

 

window.addEventListener("keydown", keyPressed.bind(this));

 

function keyPressed(evt) {
var k = evt.key.toLowerCase();
if (k=="enter") {
document.getElementById("inputBox").value = "";

this.chatRecord.text = "test";
}
}

 

it works fine with setting the inputBox to blank,  but will not do anything with the chatRecord called using "this".

what am i doing wrong? can someone please help, thanks!

 

 

Views

147

Translate

Translate

Report

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 ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

you need a dynamic textfield with instance name chatRecord at the time that code executes.

Votes

Translate

Translate

Report

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
New Here ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

Hi ya, i do have the dynamic textfield named chatRecord on the stage, and everything is already fully loaded before this function is called, is there something i need to do in addition to that?

Votes

Translate

Translate

Report

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 ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

open your browser's developer console and find the error.

 

if tou don't know how to use it,

 

lesson 1 - https://youtu.be/PBDQN9CQSeI

 

lesson 2 - https://youtu.be/KJEl0OenGUY

Votes

Translate

Translate

Report

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
New Here ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

you know what i just tried my own code on a test file where nothing is sitting inside nested movieclips and it worked perfectly, so i guess my nesting somehow broke the code. I will try to figure out what went wrong, thanks!!

Votes

Translate

Translate

Report

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 ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

LATEST

the console will tell you exactly what's wrong and where the error is located.

Votes

Translate

Translate

Report

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