[flexcoders] Re: Keydownhandler fires twice for each keystroke
I found a little more information. This undesireable feature, aka bug manifests itself only if you make the combobox editable. I removed the editable=true and the problem goes away. Paul --- In flexcoders@yahoogroups.com, aceoohay [EMAIL PROTECTED] wrote: Since creating a test case would be challenging I am posting the component ValidatedComboBox.as. The problem I am having is that it appears to call the keyDownHandler(event:KeyboardEvent):void function twice for each keystroke. I have commented out most of that function's code, as it used to handle all input there but now I only handle the backspace there this is a patch to get it to function somewhat. package Classes.Input { import flash.events.Event; import mx.controls.ComboBox; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import flash.events.FocusEvent; import flash.events.MouseEvent; /** * Create an extended version of the ComboBox that allows the definition of invalid indexes. * * The developer defines one or more invalid indexes in a comma separated list using the property badIndexes. * Most commonly the developer would specify 0 which is the first element in the list. * * New properties are; * badIndexes - A string that allows the developer to define a comma separated list of invalid indexes. * isVald - A boolean that defines whether the field is valid. * * New Methods are; * validateData() - This method checks if the data is valid and returns true if valid, false if invalid. * */ public class ValidatedComboBox extends ComboBox { /** Bad indexes - A comma separated list of invalid indexes. */ private var _badIndexes:String = ; /** Has this field passed validation */ private var _isValid:Boolean = true; /** value */ private var _value:Object; /** should we validate data */ private var _doValidateData:Boolean = true; /** promptLabel */ private var _promptLabel:String; /** toolTipField */ private var _toolTipField:String = ; /** Default value A literal that represents the value that will replace the value * property when the method setDefault is executed */ private var _defaultValue:String = ; private var _eventHandler:Function = this [checkData]; private var _typedText:String = ; public function ValidatedComboBox() { //TODO: implement function super(); this.addEventListener (Event.CHANGE,_eventHandler) } /** * Add a new inspectable property so the user can enter the Bad Indexesn * at authortime via the properties panel. * * @return the specified bad indexes */ [Inspectable( type=String , defaultValue= )] public function get badIndexes():String { return this._badIndexes; } /** * Sets the the specified bad indexes */ public function set badIndexes( badIndexes:String ):void { this._badIndexes = badIndexes; } /** * Add a new inspectable property so the user can enter the promptLabel for the field * at authortime via the properties panel. * * @return the specified promptLabel */ [Inspectable( type=String , defaultValue= )] public function get promptLabel():String { return this._promptLabel; } /** * Sets the the specified promptLabel */ public function set promptLabel( promptLabel:String ):void { this._promptLabel = promptLabel; } /** * Add a new inspectable property so the user can specify the whether this field should be validated * via the properties panel. * * @return the specified validate data flag. */ [Inspectable( type=Boolean , defaultValue=false, enumeration=true,false )] public function get doValidateData():Boolean {
RE: [flexcoders] Re: Keydownhandler fires twice for each keystroke
If you override keyDownHandler, you shouldn't need to call addEventListener since the base class will. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Saturday, August 30, 2008 12:07 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Keydownhandler fires twice for each keystroke I found a little more information. This undesireable feature, aka bug manifests itself only if you make the combobox editable. I removed the editable=true and the problem goes away. Paul --- In flexcoders@yahoogroups.commailto:flexcoders%40yahoogroups.com, aceoohay [EMAIL PROTECTED] wrote: Since creating a test case would be challenging I am posting the component ValidatedComboBox.as. The problem I am having is that it appears to call the keyDownHandler(event:KeyboardEvent):void function twice for each keystroke. I have commented out most of that function's code, as it used to handle all input there but now I only handle the backspace there this is a patch to get it to function somewhat. package Classes.Input { import flash.events.Event; import mx.controls.ComboBox; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import flash.events.FocusEvent; import flash.events.MouseEvent; /** * Create an extended version of the ComboBox that allows the definition of invalid indexes. * * The developer defines one or more invalid indexes in a comma separated list using the property badIndexes. * Most commonly the developer would specify 0 which is the first element in the list. * * New properties are; * badIndexes - A string that allows the developer to define a comma separated list of invalid indexes. * isVald - A boolean that defines whether the field is valid. * * New Methods are; * validateData() - This method checks if the data is valid and returns true if valid, false if invalid. * */ public class ValidatedComboBox extends ComboBox { /** Bad indexes - A comma separated list of invalid indexes. */ private var _badIndexes:String = ; /** Has this field passed validation */ private var _isValid:Boolean = true; /** value */ private var _value:Object; /** should we validate data */ private var _doValidateData:Boolean = true; /** promptLabel */ private var _promptLabel:String; /** toolTipField */ private var _toolTipField:String = ; /** Default value A literal that represents the value that will replace the value * property when the method setDefault is executed */ private var _defaultValue:String = ; private var _eventHandler:Function = this [checkData]; private var _typedText:String = ; public function ValidatedComboBox() { //TODO: implement function super(); this.addEventListener (Event.CHANGE,_eventHandler) } /** * Add a new inspectable property so the user can enter the Bad Indexesn * at authortime via the properties panel. * * @return the specified bad indexes */ [Inspectable( type=String , defaultValue= )] public function get badIndexes():String { return this._badIndexes; } /** * Sets the the specified bad indexes */ public function set badIndexes( badIndexes:String ):void { this._badIndexes = badIndexes; } /** * Add a new inspectable property so the user can enter the promptLabel for the field * at authortime via the properties panel. * * @return the specified promptLabel */ [Inspectable( type=String , defaultValue= )] public function get promptLabel():String { return this._promptLabel; } /** * Sets the the specified promptLabel */ public function set promptLabel( promptLabel:String ):void { this._promptLabel = promptLabel; } /** * Add a new inspectable property so the user can specify the whether this field should be validated * via the properties panel. * * @return the specified validate data flag. */ [Inspectable( type=Boolean , defaultValue=false, enumeration=true,false )] public function get doValidateData():Boolean { return this._doValidateData; } /** * Sets the specified validate data flag. */ public function set doValidateData( doValidateData:Boolean ):void { this._doValidateData = doValidateData; } /** * Add a new inspectable property so the user can enter the tool Tip Field for the field * at authortime via the properties panel. * * @return the specified toolTipField */ [Inspectable( type=String , defaultValue= )] public function get toolTipField():String { return this._toolTipField; } /** * Sets the the specified toolTipField */ public function set toolTipField( toolTipField:String ):void { this._toolTipField =toolTipField; } /** * Add a new inspectable property so the user can enter a Default value * at authortime via the properties panel. * * @return the specified Maximum value */ [Inspectable( type=String , defaultValue= )] public function get defaultValue():String { return this._defaultValue; } /** * Sets the specified Default value */ public function set defaultValue
[flexcoders] Re: Keydownhandler fires twice for each keystroke
Since creating a test case would be challenging I am posting the component ValidatedComboBox.as. The problem I am having is that it appears to call the keyDownHandler(event:KeyboardEvent):void function twice for each keystroke. I have commented out most of that function's code, as it used to handle all input there but now I only handle the backspace there this is a patch to get it to function somewhat. package Classes.Input { import flash.events.Event; import mx.controls.ComboBox; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import flash.events.FocusEvent; import flash.events.MouseEvent; /** * Create an extended version of the ComboBox that allows the definition of invalid indexes. * * The developer defines one or more invalid indexes in a comma separated list using the property badIndexes. * Most commonly the developer would specify 0 which is the first element in the list. * * New properties are; * badIndexes - A string that allows the developer to define a comma separated list of invalid indexes. * isVald - A boolean that defines whether the field is valid. * * New Methods are; * validateData() - This method checks if the data is valid and returns true if valid, false if invalid. * */ public class ValidatedComboBox extends ComboBox { /** Bad indexes - A comma separated list of invalid indexes. */ private var _badIndexes:String = ; /** Has this field passed validation */ private var _isValid:Boolean = true; /** value */ private var _value:Object; /** should we validate data */ private var _doValidateData:Boolean = true; /** promptLabel */ private var _promptLabel:String; /** toolTipField */ private var _toolTipField:String = ; /** Default value A literal that represents the value that will replace the value * property when the method setDefault is executed */ private var _defaultValue:String = ; private var _eventHandler:Function = this [checkData]; private var _typedText:String = ; public function ValidatedComboBox() { //TODO: implement function super(); this.addEventListener (Event.CHANGE,_eventHandler) } /** * Add a new inspectable property so the user can enter the Bad Indexesn * at authortime via the properties panel. * * @return the specified bad indexes */ [Inspectable( type=String , defaultValue= )] public function get badIndexes():String { return this._badIndexes; } /** * Sets the the specified bad indexes */ public function set badIndexes( badIndexes:String ):void { this._badIndexes = badIndexes; } /** * Add a new inspectable property so the user can enter the promptLabel for the field * at authortime via the properties panel. * * @return the specified promptLabel */ [Inspectable( type=String , defaultValue= )] public function get promptLabel():String { return this._promptLabel; } /** * Sets the the specified promptLabel */ public function set promptLabel( promptLabel:String ):void { this._promptLabel = promptLabel; } /** * Add a new inspectable property so the user can specify the whether this field should be validated * via the properties panel. * * @return the specified validate data flag. */ [Inspectable( type=Boolean , defaultValue=false, enumeration=true,false )] public function get doValidateData():Boolean { return this._doValidateData; } /** * Sets the specified validate data flag. */
[flexcoders] Re: Keydownhandler fires twice for each keystroke
have you called addEventListener twice? --- In flexcoders@yahoogroups.com, aceoohay [EMAIL PROTECTED] wrote: nope... After you posted I inserted; event.preventDefault(); At the beginning of the function with no effect. Like I said it seems as though the keyDownHandler function is called twice for each keystroke. Paul --- In flexcoders@yahoogroups.com, Tracy Spratt tspratt@ wrote: Event.preventDefault? Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Monday, August 18, 2008 4:46 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Keydownhandler fires twice for each keystroke Flex 2.0.1 I am trying to capture keystrokes in the keyDownHandler of a ComboBox and it appears to be firing twice for each keystroke. Any ideas on what might cause this? The code below works except that when the user strikes a backSpace it removes two characters from _typedText. Paul override protected function textInput_changeHandler (event:Event):void { _typedText += this.textInput.text; if (!findFirstItem(_typedText)) { _typedText = _typedText.substr (0,_typedText.length -1); findFirstItem(_typedText); } } override protected function keyDownHandler (event:KeyboardEvent):void { if(!event.ctrlKey) { if (event.keyCode == Keyboard.BACKSPACE || event.keyCode == Keyboard.DELETE) { _typedText = _typedText.substr(0,_typedText.length -1); findFirstItem(_typedText); } } }
[flexcoders] Re: Keydownhandler fires twice for each keystroke
nope... After you posted I inserted; event.preventDefault(); At the beginning of the function with no effect. Like I said it seems as though the keyDownHandler function is called twice for each keystroke. Paul --- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote: Event.preventDefault? Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Monday, August 18, 2008 4:46 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Keydownhandler fires twice for each keystroke Flex 2.0.1 I am trying to capture keystrokes in the keyDownHandler of a ComboBox and it appears to be firing twice for each keystroke. Any ideas on what might cause this? The code below works except that when the user strikes a backSpace it removes two characters from _typedText. Paul override protected function textInput_changeHandler (event:Event):void { _typedText += this.textInput.text; if (!findFirstItem(_typedText)) { _typedText = _typedText.substr (0,_typedText.length -1); findFirstItem(_typedText); } } override protected function keyDownHandler (event:KeyboardEvent):void { if(!event.ctrlKey) { if (event.keyCode == Keyboard.BACKSPACE || event.keyCode == Keyboard.DELETE) { _typedText = _typedText.substr(0,_typedText.length -1); findFirstItem(_typedText); } } }
RE: [flexcoders] Re: Keydownhandler fires twice for each keystroke
keyDown is not cancelable. Post a test case so we can see how you wired it up. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Monday, August 18, 2008 3:01 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Keydownhandler fires twice for each keystroke nope... After you posted I inserted; event.preventDefault(); At the beginning of the function with no effect. Like I said it seems as though the keyDownHandler function is called twice for each keystroke. Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Tracy Spratt [EMAIL PROTECTED] wrote: Event.preventDefault? Tracy From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of aceoohay Sent: Monday, August 18, 2008 4:46 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Keydownhandler fires twice for each keystroke Flex 2.0.1 I am trying to capture keystrokes in the keyDownHandler of a ComboBox and it appears to be firing twice for each keystroke. Any ideas on what might cause this? The code below works except that when the user strikes a backSpace it removes two characters from _typedText. Paul override protected function textInput_changeHandler (event:Event):void { _typedText += this.textInput.text; if (!findFirstItem(_typedText)) { _typedText = _typedText.substr (0,_typedText.length -1); findFirstItem(_typedText); } } override protected function keyDownHandler (event:KeyboardEvent):void { if(!event.ctrlKey) { if (event.keyCode == Keyboard.BACKSPACE || event.keyCode == Keyboard.DELETE) { _typedText = _typedText.substr(0,_typedText.length -1); findFirstItem(_typedText); } } }