Groups | Blog | Home
all groups > flash actionscript > december 2004 >

flash actionscript : Character x and y position into a textField



David Stiller
12/3/2004 3:27:32 PM
Nope. Wish it was, too!


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

David Stiller
12/3/2004 4:19:01 PM
NSurveyor,

I haven't read through all your code yet, but are you saying it creates
as many text fields as there are words, so that each word can be checked
because it exists as its own text field? If so, that is a workaround (about
the only one I can think of). I would wonder, though, how much that would
cause the CPU to chug, given the possibility for thousands of words.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

David Stiller
12/3/2004 4:57:26 PM
Aha. Nice approach. The more I think about that, that's a *really*
nice approach.

As it turns out, you may be able to use the TextFormat.getTextExtent()
method instead of going to the trouble of creating a new text field. This
is an idea worth toying with. Good inspiration!


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

David Stiller
12/3/2004 5:26:36 PM
Look at TextFormat.getTextExtent(). You can pass a string to that
method and get the length of that string based on font family, font size,
and so on. In the Flash 7 Player, you can even specify the width of the
text field.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Radio
12/3/2004 7:55:38 PM
Hello guys. Is it possible to find the x and y position of a given character
into a textField? I mean, if I know the position of that caracter in terms of
the total number of caracters, can I find its _x and its _y, like in Director?
Thanks so much. :music;
NSurveyor
12/3/2004 9:07:21 PM
I'm not quite sure if this script works competely, but it's worth a shot:
charXY(INSTANCENAMEOFTEXTBOX,INDEXOFCHAR)._x;//This is the _x of the char at
the INDEXOFCHAR
charXY(INSTANCENAMEOFTEXTBOX,INDEXOFCHAR)._y;//This is the _y of the char at
the INDEXOFCHAR
function charXY (st,theCharAt) {
createTextField("testText",1,st._x,st._y,st._width,st._height);
testFormat = new TextFormat();
for(props in st){
testText[props] = st[props]
}
for(item in st.getTextFormat()){
testFormat[item] = st.getTextFormat()[item]
}
testText.setNewTextFormat(testFormat);
ctext = testText.text;
partText = new String();
for(ccount = 0;ccount<=theCharAt;ccount++){
partText+=ctext.charAt(ccount);
}
testText.text = partText;
coor = new Object();
coor._y = testText.textHeight+testText._y;
coor._x = testText.textWidth+testText._x;
testText.text = ctext;
delete(textText);
return coor;
}

NSurveyor
12/3/2004 9:09:54 PM
It's a long work around, that probably doesn't work competely. Basically, it
duplicates a text box, but this textbox will only have the characters up to the
given index. Then, it adds the _x of the textbox with the textWidth of the new
textbox, and it adds the _y of the textbox with the textHeight, and returns
those two values as, charXY(myTextbox,someIndex)._x and
charXY(myTextbox,someIndex)._y
NSurveyor
12/3/2004 9:44:33 PM
No, only one textfield is made. It make a textbox identical to the original,
but only contains up to a certain amount of characters. Then I used
_x+textWidth and _y+textHeight to figure out where the last charachter in the
textbox is (and because it is limited to a specified character, the last
character is the specified character)
NSurveyor
12/3/2004 9:48:04 PM
But, I think this script will only work on textboxes with Left-Alignment,
because the abscence of characters in a textbox with Center Alignment and Right
Alignment will change the _x and _y of most characters.
NSurveyor
12/3/2004 10:00:24 PM
Actually, I don't think my script really works. the textHeight and textWidth of
multilined textboxes will not really help me get the last character of that
line's x and y. And that's what I was trying to do. Oh well, it almost worked...
AddThis Social Bookmark Button