# TextField selection. Stopping default behavior

**URL:** <https://forum.kirupa.com/t/textfield-selection-stopping-default-behavior/315033>\
**Category:** Uncategorized\
**Created:** [October 15, 2010, 3:58pm UTC](https://forum.kirupa.com/t/textfield-selection-stopping-default-behavior/315033 "2010-10-15T15:58:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenBart](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@BenBart](https://forum.kirupa.com/u/BenBart)\
**Post date:** [October 15, 2010, 3:58pm UTC](https://forum.kirupa.com/t/textfield-selection-stopping-default-behavior/315033/1 "2010-10-15T15:58:42Z")

</div>

I have a dynamic TextField with code on it. Normally, if you select text and then hit the up key your selection would move up. I want to prevent this behavior, because I’m using the UP key to tighten the leading.

I would think that “e.stopPropagation();” but then I realized that the event is happening on the same place.

The only thing I could think of is to capture the [selectionBeginIndex and the [URL=“http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html#selectionEndIndex”]selectionEndIndex and then after the KeyboardEvent call the [URL=“http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html#setSelection%28%29”]setSelection](http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html#selectionBeginIndex) method.

Any thoughts?

```auto

kerningTextField.addEventListener(KeyboardEvent.KEY_DOWN, updateKerning)

function updateKerning(e:KeyboardEvent)
{
    
    if(e.shiftKey)
    {
        trace("keyboardEvent with shift pressed");
        var currentTextFormat:TextFormat
        switch(e.keyCode) //Up Key
        {
            case 38: //Up key
            currentTextFormat = kerningTextField.getTextFormat();
            trace(currentTextFormat.leading);
            currentTextFormat.leading = Number(currentTextFormat.leading) - 1;
            kerningTextField.setTextFormat(currentTextFormat);
            e.stopPropagation();
            break;
            
            case 40: //Down key
            currentTextFormat = kerningTextField.getTextFormat();
            trace(currentTextFormat.leading);
            currentTextFormat.leading = Number(currentTextFormat.leading) + 1;
            kerningTextField.setTextFormat(currentTextFormat);
            e.stopPropagation();
            break;
        }
    }
}

```
