I have an input text box with the instance name of input_txt and a dynamic text field named output_txt. I'm trying to do something with the dynamic field when the user has entered text into the input field. So far, this is what I have:
input_txt.addEventListener(TextEvent.TEXT_INPUT, update);
function update(event:TextEvent):void {
output_txt.text = "foobar";
}
I don't know if this is valid ActionScript 3.0. I am getting an error that says "the class 'TextEvent' could not be loaded." What am I doing wrong?
-
I've done something similar. But I listened to the CHANGE event instead. You can try that- it's a bit tricky since it can be thrown sometimes when the field isn't actually changed.
so listen to (Event.CHANGE, update);
Andrew : I got the same results: "the class or interface 'Event' could not be loaded". What should I do differently?martinlindelof : import flash.events.*; import ALL Event classes and see if it works. ^_+ -
Perhaps you're missing "import flash.events.TextEvent"? Also, you should probably put your code in an action script file (*.as), rather than putting it within a specific frame.
Andrew : I added "import flash.events.TextEvent" to the top of my code and I'm getting the error "the class or interface 'flash.events.TextEvent' could not be loaded" in addition to "the class or interface 'TextEvent' could not be loaded". Did I type something wrong? -
You are propably working in a Actionscript 2.0 .fla.
Create new file > Actionscript 3.0You don't need to import on timeline scripts, just put the textboxes and your original code and you'll propably be fine.
Andrew : you were totally right. I don't know how it ended up being 2.0, but once I created a new file, it worked fine. And like you said, no need to "import flash.events.*"amoeba : Cheers, good luck! -
Check to see what results you get using
TextEvent.TEXT_INPUT
vs
Event.CHANGE
I had issues with the TEXT_INPUT lagging user update by one character, so I switched to the CHANGE event.
0 comments:
Post a Comment