Actually the best way I found is the following:
package XYZ
{
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.TextEvent;
import mx.events.FlexEvent;
import spark.components.TextArea;
public class TextAreaClosingSoftKeyboardOnEnter extends TextArea
{
public function TextAreaClosingSoftKeyboardOnEnter()
{
super();
addEventListener(TextEvent.TEXT_INPUT, handleChange);
// This is for clicking somewhere outside the
TextArea
addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,
handleMouseFocusChanged);
}
private function handleChange(event:Event):void
{
if(text.indexOf("\r") != -1 || text.indexOf("\n") != -1)
{
text = text.replace(/[\r\n]/g, "");
closeSoftKeyboard();
event.preventDefault();
return;
}
}
private function closeSoftKeyboard():void
{
stage.focus = null;
}
protected function
handleMouseFocusChanged(event:FocusEvent):void
{
if(!event || !stage)
{
return;
}
if(!(event.relatedObject is TextArea))
{
closeSoftKeyboard();
}
}
public function dispose():void
{
removeEventListener(Event.CHANGE, handleChange);
removeEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,
handleMouseFocusChanged);
}
}
}
--
View this message in context:
http://apache-flex-users.2333346.n4.nabble.com/Getting-Enter-Clicked-event-Flex-Mobile-iOs-spark-skins-mobile-TextAreaSkin-tp2618p2692.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.