Skip to main content
Inspiring
May 29, 2023 12:35 PM UTC
Answered

The (x,y) coordinates in the text field are out of range of the field.

I have a text field with many lines.
While checking the (x,y) coordinates of the field, I came across an incomprehensible problem.
The (x,y) coordinates in the text field are out of range of the field.

Why this problems occurred,
Please let me know if You can solve it.
I want to make the field's base point coordinates be (0,0).
Thank you

// sm => list Array
// There are no blanks before each character in the array.

for (var i: uint = 0; i < sm.length; i++) {
    var tx: String = (i < sm.length - 1) ? "\n" : " ";
    musicList.appendText(sm[i] + tx);
}
DisplayObject(musicList);
musicList.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);

function mouseOutHandler(e: MouseEvent): void {
    var topOut: Number = e.localY;
    var leftOut: Number = e.localX;
    var bottomOut: Number = e.localY;

    // textField.height => 373.95
    // The coordinates fluctuate slightly from time to time... For example

    trace("TopOut    : " + topOut); // 7.999603271484375 ( Top > 0 )
    trace("LeftOut   : " + leftOut); // -2.3534393310546875 ( Left < 0 )
    trace("BottomOut : " + bottomOut); // 382.3807067871094 (Bottom > textField.height )
}
    This topic is closed to new replies. Start a new post to keep the conversation going.
    kglad
    kgladCorrect answer
    Community Expert
    May 29, 2023 1:13 PM UTC

    localX and localY is a little funky, but your naming isn't helping things.  ie, there is no left, top, bottom.  it's the x and y, only.

     

    anyway, it's more intuitive to use mouseX and mouseY.  if you want those relative to the object, use the object's corner coordinates.

    3 replies

    Inspiring
    Jun 1, 2023 8:13 AM UTC

    It will take a lot of time to fix my code, but your advice is correct.
    Thank you

    Translate
    kglad
    Community Expert
    Community Expert
    Jun 1, 2023 1:11 PM UTC

    you're welcome.

     

     

    Translate
    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    May 29, 2023 1:13 PM UTC

    localX and localY is a little funky, but your naming isn't helping things.  ie, there is no left, top, bottom.  it's the x and y, only.

     

    anyway, it's more intuitive to use mouseX and mouseY.  if you want those relative to the object, use the object's corner coordinates.

    Translate