TextInput Component event is not working
I am working on a AS3 only project in Flex....I tried to listen ENTER event when use clicks enter/return in my textinput box....but it seems not working well...I did try using TextEvent.TEXT_INPUT and it worked fine but not Component.ENTER...any help??? Thanks a lot!!
import fl.events.ComponentEvent;
searchInput=new TextField();
searchInput.type=TextFieldType.INPUT;
searchInput.background=true;
searchInput.backgroundColor=0xecffee;
searchInput.defaultTextFormat=TF;
searchInput.width = 200;
searchInput.height=16;
searchInput.x=50;
searchInput.y=180;
addC开发者_运维技巧hild(searchInput);
searchInput.addEventListener(ComponentEvent.ENTER, testEnter);
}
private function testEnter(e:ComponentEvent):void{
if(searchInput.text!=null){
beginSearch(searchInput.text);
}
searchInput.selectable = true;
and maybe
searchInput.mouseEnabled = true;
try this then:
searchInput.addEventListener(MouseEvent.CLICK, testEnter);
private function testEnter(event:MouseEvent):void
{
}
sorry, i was bit too quick on that one...
here it is
searchInput=new TextInput();
TextField doesn't extend the UIComponent class , therefore it can't handle ComponentEvent. Instead of telling you to change the event , I should have told you to change the event handler. My understanding is that you write AS3 projects with Flex so I looked at the TextField first!
I'm not sure if you can use the TextInput class in an AS3 project since it's part of the Flex framework...
in which case you may have to revert to the MouseEvent but not triggered by the TextField though but by a simple 'Search' button
The event you're looking for is 'change' / flash.events.Event.CHANGE
which is dispatched when the control value is modified. The flex documentation is quite helpful here: Flex 3 TextInput
If you want to listen to the user pressing ENTER you should use the keyDown-event. Otherwise (like also mentioned) you can use the change-event.
As you are using the TextField-component the right documentation is link text
The TextInput-component has also an valueCommit-event, maybe you can use this one...
精彩评论