shoosh
shoosh

Reputation: 79021

ActionScript 3 Newb: TextInput enter event?

I'm trying to capture the ENTER event of a TextInput like so:

a_txt.addEventListener(fl.events.ComponentEvent.ENTER, aEnter);

function aEnter(ComponentEvent):void 
{
    //...
}

There's probably something in these docs
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/controls/TextInput.html#event:enter
which I don't quite understand because I'm getting this compile error:

1120: Access of undefined property fl.

What am I doing wrong?

Upvotes: 3

Views: 4766

Answers (3)

Ross Henderson
Ross Henderson

Reputation: 1779

I think you want the textInput event, rather than the enter.

The enter event fires when the user presses the Enter/Return key. The textInput event fires whenever the user types, deletes, or pastes.

Hope that helps.

Upvotes: 0

AndrewB
AndrewB

Reputation: 972

Think that you want the textEvent then tie this to your normal

function aEnter(e:TextEvent):void {
    if (evt.text == "\n") {
       evt.preventDefault();
       // Do some thing else??
    }
}

Upvotes: 1

Paul Chernoch
Paul Chernoch

Reputation: 5563

I am not sure. I always use an import statement instead of qualifying with package names. Try adding:

import fl.events.ComponentEvent;

and then change your code to:

a_txt.addEventListener(ComponentEvent.ENTER, aEnter);

function aEnter(e:ComponentEvent):void 
{
    //...
}

Note: I also added an argument name "e" to the function call declaration.

Upvotes: 2

Related Questions