Instead of using focusOut and focusIn I used keyDown and mouseUp and that seemed to do the trick.  It may not be perfect all the time, I’d imagine you can type fast enough and maybe confuse it, but this should get you going.

 

Matt

 


From: [email protected] [mailto:[email protected]]
Sent: Thursday, April 21, 2005 4:43 AM
To: [email protected]
Subject: [flexcoders] Re: TextArea help

 


Matt

The Selection.getCartIndex() doesn't seem to work, I've tried to call
it when I loose or gain focus within the textArea control.
Irrespective of where the cursor is within the text area the
Selection.getCartIndex() seems to return "0" or "-1"; naturally there
is text inside the text area.

Do you have an instance where it's been used correctly, I been through
the MM web documentation and have failed to get it to work.

I include my test bed. Am I using it correctly?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >
      <mx:Script>
      <![CDATA[

      private var nCurPos:Number = -2;

      private function getCurPos(event):Void
      {
            this.nCurPos = Selection.getCaretIndex();
      }

      private function myAddTextToTxtArea(event):Void
      {
            var sValue = event.target.selectedItem;

            var text:String = txaTop.text;
            //
            var start: String = text.substring(0, nCurPos);
            var end: String = text.substring(nCurPos);
            var whole: String = start +" "+ sValue +" "+ end;
            txaTop.text = whole;
      }

      function showCaretIndex():Void
      {
            this.lblX.text =".getCaretIndex() return Position
"+nCurPos.toString()+"\n"+this.txaTop.text;
      }

      ]]>
      </mx:Script>

      <mx:HBox width="100%" height="60%">
            <mx:Panel width="220" height="100%">
                  <mx:List id="dgIF" width="100%" height="100%"
change="myAddTextToTxtArea(event);">
                        <mx:dataProvider>
                              <mx:Array>
                                    <mx:String>International</mx:String>
                                    <mx:String>Jewel</mx:String>
                                    <mx:String>Thief</mx:String>
                              </mx:Array>
                        </mx:dataProvider>
                  </mx:List>
            </mx:Panel>

            <mx:Panel width="90%" height="100%">
                  <mx:TextArea id="txaTop"
focusIn="getCurPos(event);showCaretIndex();"
focusOut="getCurPos(event);showCaretIndex();" editable="true"
width="350" height="80%" />
                  <mx:Label id="lblX" width="100%" color="#FF0000" height="40"/>
                  <mx:Button label="Show Cart Position &amp; Data"
click="showCaretIndex();" />
            </mx:Panel>
      </mx:HBox>

</mx:Application>

Thanks you.


--- In [email protected], Matt Chotin <[EMAIL PROTECTED]> wrote:
> Check out the Selection.getCaretIndex() function maybe?  I haven't tried
> this but you could probably do something like this:
>

>
> var text : String = myTA.text;
>
> var idx : Number = Selection.getCaretIndex();
>
> var start : String = text.substring(0, idx);
>
> var end : String = text.substring(idx);
>
> var whole : String = start + "my new text" + end;
>
> myTA.text = whole;
>

>
> Matt
>

>
>   _____ 
>
> From: [email protected] [mailto:[email protected]]
> Sent: Wednesday, April 20, 2005 8:45 AM
> To: [email protected]
> Subject: [flexcoders] TextArea help
>

>
>
> Hello to all flex masters
>
> Can somebody tell me how to programmatically enter a piece of text
> into a specific position within a TextArea that already contains a
> block of text.
>
> I have a TextArea containing a block of text. I am trying to insert
> additional text into an arbitrary position within the already existing
> block of text. I want to select the text insert position using the
> MOUSE cursor then click a button to add text to the previously
> selected position.
>
> A code example/snippet would be most helpful.
>
> Thanks in advance
>
>
>
>
>
>
>   _____ 
>
> Yahoo! Groups Links
>
> *      To visit your group on the web, go to:
> http://groups.yahoo.com/group/flexcoders/
> <http://groups.yahoo.com/group/flexcoders/>
>  
> *      To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
>  
> *      Your use of Yahoo! Groups is subject to the Yahoo!
> <http://docs.yahoo.com/info/terms/>  Terms of Service.






Yahoo! Groups Links

Reply via email to