| <?xml version="1.0" encoding="utf-8"?>
|
| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| |
| --> |
| <mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" keyUp="textBox_keyUp(event)" change="textBox_change()">
|
|
|
| <mx:Script>
|
| <![CDATA[
|
|
|
| public static const TEXT_SUBMIT:String = "textSubmit";
|
| private var isDirty:Boolean = false;
|
| private var typingPauseTimer:Timer;
|
|
|
| private function init():void
|
| {
|
| typingPauseTimer = new Timer(700, 1);
|
| typingPauseTimer.addEventListener(TimerEvent.TIMER, timer_typingPause);
|
| }
|
|
|
| private function textBox_change():void
|
| {
|
| isDirty = true;
|
|
|
| if(typingPauseTimer.running)
|
| typingPauseTimer.reset();
|
| typingPauseTimer.start();
|
| }
|
|
|
| private function timer_typingPause(event:TimerEvent):void
|
| {
|
| if(isDirty)
|
| submitText();
|
| }
|
|
|
| private function textBox_keyUp(event:KeyboardEvent):void
|
| {
|
| if(event.keyCode == Keyboard.ENTER && isDirty)
|
| submitText();
|
| }
|
|
|
| private function submitText():void
|
| {
|
| var notificationTimer:Timer = new Timer(100, 1);
|
| notificationTimer.addEventListener(TimerEvent.TIMER, timer_turnNotificationOff);
|
| notificationTimer.start();
|
|
|
| isDirty = false;
|
| this.setStyle("backgroundColor", 0xFFFFB3);
|
| dispatchEvent(new Event(TEXT_SUBMIT, true));
|
| }
|
|
|
| private function timer_turnNotificationOff(event:TimerEvent):void
|
| {
|
| this.setStyle("backgroundColor", 0xFFFFFF);
|
| }
|
|
|
| ]]>
|
| </mx:Script>
|
|
|
| <mx:Metadata>
|
| [Event(name="textSubmit", type="flash.events.Event")]
|
| </mx:Metadata>
|
|
|
| </mx:TextInput>
|