Skip to main content
alexr58234163
Known Participant
July 18, 2024
Answered

Why??? Definition 1172:  Definition fl events.ComponentEvent could not be found.

  • July 18, 2024
  • 2 replies
  • 2779 views

I am trying to ask for input in an input textfield and the way Im doing it is using

 

 

import fl.events.ComponentEvent;
input_text.addEventListener(ComponentEvent.ENTER, readInput);
input_text.addEventListener(Event.CHANGE, changeHandler);

var clearing:Boolean=false;

function readInput(event:Event):void
{
    input = input_txt.text;
    trace(input);

    clearing=true;

}

function changeHandler(event:Event)
{
if(clearing)
{
  input_text.text="";
  clearing=false;
}
}

 

 

in my code, however am getting a Definition 1172:  Definition fl events.ComponentEvent could not be found.

I am only doing all of this junk instead of a simple input_text="" on a keycode=13 event listener; because when i do that it adds a blank return line "

 "to the input when they hit enter and I dont want that. They told me i could do this and it would solve the blank extra return line problem (when i ask a person hit enter to submit the text) but they didnt mention that there would be this error. What do i do

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

Hello. I executed the code. Three things are undesirable.

1. Chat is not starting directly above the text input, nor is it bottom-aligned like I wanted.

2   Responses are not ascending as they are later.  My original method of "chathistoryline1/2/3/4" is fine and it beats this because it allows to push most latest responses upward and out of the chat history

3. Still getting undesired break line after hitting enter, and the cursor proceeds to line 2 undesired, and you have to backspace to delete the break line

6, Pressing backspace and typing and hitting enter will either place new text directly beside the previous line or on a new line

https://youtu.be/9E0kEFKI_SY

 

I have my little method I just need to know how to stop and ive been also reading the other users response on how to split and join but i just cant figure out what to do


You'll have problems by using multiple text fields if the user inserts a text that takes up more than one line, I think.

Anyway, here is an approach to make the text move from bottom to top.

import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

var i:int;

function keyDownHandler(e:KeyboardEvent)
{
	if (e.keyCode == Keyboard.ENTER)
	{
		chathistory.appendText(e.currentTarget.text + "\n");
		chathistory.scrollV = chathistory.maxScrollV;
		e.currentTarget.text = "";
	}
}

for (i = chathistory.numLines - 1; i > -1; i--)
	chathistory.appendText("\n");

usertext.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);


https://drive.google.com/file/d/1LXBpsccYXIk_uUYAeigxhJjufnxCMHv0/view?usp=sharing

Please note that this is just a simple template for you to get started. This is not gonna solve all challenges required to develop a chat application.

2 replies

JoãoCésar17023019
Community Expert
Community Expert
July 19, 2024

Hi.

 

Make sure you have a TextInput added to the stage because by default Animate doesn't know where to look for components' code if you don't have any in your project or if you don't set the paths in the AS3 settings.

Regards,

JC

kglad
Community Expert
Community Expert
July 19, 2024

i don't see why you'd get that error though you have two other obvious errors:

 

input is undefined

input_txt is not input_text

alexr58234163
Known Participant
July 19, 2024

kglad, when I begin to type import, then type  fl.events. i can see a list of all the available packages, component event isn't there! Neither when using flash.events.

kglad
Community Expert
Community Expert
July 23, 2024

Hehe I would like to know how to do it with input textfield. Do you want a video of me show you what i mean or do you think you know what i mean? Ok obviously they type a little, press enter, the text box should empty and what they type should occupy in the first space directly above. However what ends up occupying is 

"

"

or 

"

the text"


if your textfield is ti, use:

 

//////////////////////////////////

ti.addEventListener(Event.CHANGE, readInput);
ti.text = "";
 
function readInput(e:Event):void {
trace(e.currentTarget.text);
/////////////////////////////////
 
then describe how you want the trace output to appear, if it's not what you want currently.
}