A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Coordinates of TEXT cursor

  1. #1
    Senior Member
    Join Date
    Feb 2005
    Posts
    237

    Coordinates of TEXT cursor

    Anyone know if its possible to find the coordinates of a text cursor in an input text box in the same way you can with the mouse pointer?

    Thanks

  2. #2
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  3. #3
    Senior Member
    Join Date
    Feb 2005
    Posts
    237
    Thanks a lot. Didn't have a clue where to start.

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    237
    Think it's a dead end though. Due to the varying widths of letters within a font, it's seems to be impossible to accurately convert the caret point number to spacial coordinates.

    Thanks anyway

  5. #5
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    Check McUshers code in the other thread ... I think it works, yet it's a work around... Yes, I agree there is not a direct method for achieving what you want.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  6. #6
    Senior Member
    Join Date
    Feb 2005
    Posts
    237
    Cheers Smilev.

  7. #7
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Oh, this would have been the right thread for it.

    To make this thread more complete (i have the hope, that somebody
    will ever use the search button) i post the idea here as well..


    Remember it is only a proof of concept, it is still unprecise and need some
    tweaking..
    I think the order of the letters in the checkTxtX field for the x-coordinate has to
    be reversed. Maybe i you don't wanna do it, i have a deeper look into it...
    either of who finish the script should post it in the OpenFla section.

    [fla removed, see next post]
    Last edited by McUsher; 11-23-2005 at 08:48 PM.
    My letters on the F1 key have faded, how are yours today?

  8. #8
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    I was too curious and had a further look,
    it turned out, that the property "textWidth" was too unprecise
    on a text in stage, i had to create the "X-Check" text dynamically..

    Here is the new Fla,

    Which is very precise now, but lacks some linebreak issues..
    (and i am not sure if i really fixed that infinite loop i was
    running into with the two while() loops)


    Fla should be MX2004
    Attached Files Attached Files
    My letters on the F1 key have faded, how are yours today?

  9. #9
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Just in case, someone ever finds this thread, here is a correction, that makes the calculation very precise, there might be errors still in it though.

    AS1, FP6:
    PHP Code:
    var iT inputTextField;
    iT.text "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque vel quam. Aliquam lectus arcu, semper quis, consequat sit amet, tempor sit amet, enim. Ut mattis. Cras sit amet nunc et sem ornare suscipit. ";
    var 
    tmpHeight;
    var 
    tf iT.getTextFormat();

    this.createTextField("checkTxt"1iT._x iT._widthiT._yiT._widthiT._height);
    checkTxt.border true;
    checkTxt.wordWrap true;
    checkTxt.setNewTextFormat(tf);

    this.createTextField("checkTxtX"2iT._xiT._y+iT._heightiT._width20);
    checkTxtX.border true;
    checkTxtX.setNewTextFormat(tf);



    this.onEnterFrame = function () {
        
    // calculation y position of the caret.
        
    var caretPos Selection.getCaretIndex();
        var 
    nextSpace iT.text.indexOf(" ",caretPos);
        var 
    indexForHeight = (nextSpace > -1) ? nextSpace caretPos;
        
    checkTxt.text iT.text.substr(0indexForHeight);
        
    marker._y iT._y+checkTxt.textHeight;
        
        
    // calculation of the x position
        
    tmpHeight checkTxt.textHeight;
        
    checkTxt.text iT.text.substr(0caretPos);
        
        var 
    savedLetters = new Array();
        while (
    checkTxt.textHeight == tmpHeight && checkTxt.textHeight && checkTxt.text.length 0) {
            
    savedLetters.push(checkTxt.text.substr(-11));
            
    checkTxt.text checkTxt.text.substr(0checkTxt.text.length-1);
        }
        while (
    checkTxt.text.substr(-11) != " " && checkTxt.text.length >0) {
            
    savedLetters.push(checkTxt.text.substr(-11));
            
    checkTxt.text checkTxt.text.substr(0checkTxt.text.length-1);
        }
        
    savedLetters.reverse();
        
    checkTxtX.text savedLetters.join("");
        
    marker._x tf.leading+tf.leftMargin+iT._x+checkTxtX.textWidth;
        

    My letters on the F1 key have faded, how are yours today?

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center