views:

1347

answers:

3

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?

+2  A: 

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.

Paul Chernoch
Right. so not it compiles but just not doing anything when I press enter in the TextInput box...
shoosh
A: 

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.

Ross Henderson
But this is exactly what I want. to get an event when Enter is pressed. but it doesn't work so I'm using the KEY_UP event.
shoosh
Sorry, shoosh - should have asked.
Ross Henderson
A: 

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??
    }
}
AndrewB