Professional Web Applications Themes

Setting caret position within a text area - Macromedia Flash Actionscript

Is there any convenient way to do this? I can find where the cursor is by using Selection.getCaretIndex(), and I can set a selection within an area by using Selection.setSelection(), but I can't seem to find how to move the cursor to a specific point within the text. Basically, I want to give the user the ability to enter some text, click on a button or a dropdown that will modify the TextFormat associated with the text area, and set focus right back on the text component to allow them to continue typing Incidentally, that brings me to my second ...

  1. #1

    Default Setting caret position within a text area

    Is there any convenient way to do this? I can find where the cursor is by
    using Selection.getCaretIndex(), and I can set a selection within an area by
    using Selection.setSelection(), but I can't seem to find how to move the cursor
    to a specific point within the text. Basically, I want to give the user the
    ability to enter some text, click on a button or a dropdown that will modify
    the TextFormat associated with the text area, and set focus right back on the
    text component to allow them to continue typing

    Incidentally, that brings me to my second problem. I've got a text field
    instance called main_txt, and a toggle button called underline_btn. When the
    user clicks on underline_btn, I modify the new text format associated with
    main_txt to toggle underlined text. When the user clicks on the button,
    main_txt loses focus. When the user click on main_txt again after toggling
    underline_btn, anything they type will show the modified TextFormat. This is
    as expected. However, if I include the call
    Selection.setFocus(_root.main_txt); within the body of my onPress event handler
    associated with underline_btn, not only does focus not shift correctly to
    main_txt, but the TextFormat changes don't appear to be reflected

    Any insight into what's going on with either problem would be much appreciated

    -Mik


    mikejan Guest

  2. #2

    Default Re: Setting caret position within a text area

    I solved the carret placing problem with just setting both params for
    Selection.setSelection at the same value

    Selection.setSelection(desiredPosition, desiredPosition)

    It didn't always work at first time. Had to write an interval, with just one
    millisecond delay. It worked propperly then.

    changeCarretInterval = setInterval(changeCarret,1
    function changeCarret()
    Selection.setSelection ([position], [position])
    clearInterval (changeCarretInterval);


    emmquadrat Guest

Similar Threads

  1. setting cursor position
    By higgins1b in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: November 30th, 04:22 AM
  2. Caret Position
    By ggleinig in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: October 31st, 05:09 PM
  3. Anyone set caret size/style in text field ?
    By ChipOfTheOldBlock in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: September 15th, 02:49 AM
  4. setting scroll bar position
    By kiaoraFiona webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 1
    Last Post: September 30th, 04:40 PM
  5. setting the projector position
    By sedgers webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 1
    Last Post: July 1st, 09:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139