Flex General/Tips

텍슨트 입력, 한글 입력 잘리는 현상 처리

로드스타 2012. 12. 28. 09:47

package com.flexx.controls

{

    import flash.events.Event;

    import flash.events.FocusEvent;

    import flash.events.KeyboardEvent;

    

    import mx.controls.TextInput;

    import mx.events.FlexEvent;

    

    [Event(name="customEnter", type="flash.events.Event")]


    public class FastTextInput extends TextInput

    {

        public function FastTextInput()

        {

            super();

            //this.setStyle("borderStyle","solid");

            this.addEventListener(FlexEvent.CREATION_COMPLETE,  onCreationComplete);

            this.addEventListener(FocusEvent.FOCUS_OUT ,  onFocusOut);      

        }


 

//엔터가 입력된 경우 띄어쓰기로 변환.    

   override public function set text(value:String):void {

    if (null != value) {

    value = value.replace(/\r\n/g, "\r");

    value = value.replace(/\r/g, " ");

   

    super.text = value;

   }

        

        

        /**

         * CREATION_COMPLETE EVENT

         * @param event

         */

[Bindable]private var toppaddvar:Number = 5;

        private function onCreationComplete(event:FlexEvent):void 

        {

            this.removeEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);

            this.textField.alwaysShowSelection = true;

this.setStyle("paddingTop",toppaddvar);

this.setStyle("paddingBottom",0);

this.setStyle("paddingLeft",0);

this.setStyle("paddingRight",0);

//this.setStyle("backgroundColor",0xC0C0AE);

        }

        

        /**

         * FOCUS_OUT

         * @param event

         */

        private function onFocusOut(e:FocusEvent ):void

        {

            this.setSelection(0,0);

        }

        

        public function get ktext():String

        {

        return textField.text;

        }

        public function set toppadd(value:Number):void {

toppaddvar = value;

this.setStyle("paddingTop",value);

}

        override protected function keyDownHandler(event:KeyboardEvent):void

        {

        if(event.keyCode == 9)

        textField.setSelection(textField.selectionBeginIndex, textField.selectionEndIndex+1);

        if(event.keyCode == 13)

        dispatchEvent(new Event('customEnter'));

       

        }

    }

}