tags:

views:

278

answers:

2

Hi,

The default behavior for textfield, when up arrow is pressed is, the cursor goes to the beginning or first character. I would like to disable this and add custom behavior when up arrow is pressed. I am able to add the custom behavior but I am not able to stop the default behavior.

Can some body please let me know how can I fix my issue.

thank you in advance. firemonk.

A: 
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    <mx:Script>
        <![CDATA[
            private function onKeyUp(event:KeyboardEvent):void {
                if ( event.keyCode == 38 ) {
                    event.preventDefault();
                }
            }
        ]]>
    </mx:Script>
    <mx:TextInput text="Try me!" keyDown="onKeyUp(event);" />
</mx:WindowedApplication>

38 is an ASCII code of the up arrow.

radekg
A: 

HI,

I have tried the example you suggested but it does not seem to work. I have printed event. cancelable and got false. I guess it is not possible to over write default behavior of up arrow for TextField. 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    <mx:Script>
        <![CDATA[
            private function onKeyUp(event:KeyboardEvent):void {
                if ( event.keyCode == 38 ) {
                    trace(event.cancelable);
                    event.preventDefault();
                    event.stopImmediatePropagation();
                }
            }
        ]]>
    </mx:Script>
    <mx:TextInput text="Try me!" keyDown="onKeyUp(event);" id="tf"/>
</mx:Application>
firemonkey
I found this in some other postKEY_DOWN and KEY_UP can not be canceled. cancelable is false; there is no default behavior to cancel To change all text that was entered - you should use TEXT_INPUT event which is cancelable
firemonkey