Highlighted

TextField.getCharBoundaries() not working as expected

New Here ,
Feb 24, 2011

Copy link to clipboard

Copied

Hello. I got an group chat project going on and had a problem with the TextField. The scenario is as follows: there is a public (mass) chat and a privat chats.. Like IRC! The problem is that when someone writes with smilies all appears fine.. until the moment the textfield got full and needs to be scrolled. Then the chat text appears but the getCharBoundaries returns null for the character that is on the last line: e.g. the line that has been just added and is still not scrolled to it.

Here is a screenshot:

z.png

You can see the after the scroller was scrolled down (and set scroll to maxScroll on TextField), the ":P" is not correctly displayed.

And here is the reason, according to the trace() message:

     Replace[0] = ":P" @ 394
     r == null @ idx #394/397, found there: ':'

Where 394 is the index of the smilie and 397 is the total length according to TextField.length property. So the index I request is there for sure.. It's just that getCharBoundaries(394) gives me null. Why?

http://www.actionscript.org/forums/showthread.php3?p=792090

I found an "may be" answer but still about to test if that's the problem in my case.. although when I trace the "found there" it appears non new line character... Anyway I would appretiate someone from adobe to comment over this behavior of the TextField.

Topics

ActionScript

Views

2.7K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

TextField.getCharBoundaries() not working as expected

New Here ,
Feb 24, 2011

Copy link to clipboard

Copied

Hello. I got an group chat project going on and had a problem with the TextField. The scenario is as follows: there is a public (mass) chat and a privat chats.. Like IRC! The problem is that when someone writes with smilies all appears fine.. until the moment the textfield got full and needs to be scrolled. Then the chat text appears but the getCharBoundaries returns null for the character that is on the last line: e.g. the line that has been just added and is still not scrolled to it.

Here is a screenshot:

z.png

You can see the after the scroller was scrolled down (and set scroll to maxScroll on TextField), the ":P" is not correctly displayed.

And here is the reason, according to the trace() message:

     Replace[0] = ":P" @ 394
     r == null @ idx #394/397, found there: ':'

Where 394 is the index of the smilie and 397 is the total length according to TextField.length property. So the index I request is there for sure.. It's just that getCharBoundaries(394) gives me null. Why?

http://www.actionscript.org/forums/showthread.php3?p=792090

I found an "may be" answer but still about to test if that's the problem in my case.. although when I trace the "found there" it appears non new line character... Anyway I would appretiate someone from adobe to comment over this behavior of the TextField.

Topics

ActionScript

Views

2.7K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 28, 2011

Copy link to clipboard

Copied

Good news, everyone! I solved the issue. The problem appears only when the text is not scrolled to the line I want to get char boundaries. E.g. if the text field can show 10 lines of text, and the scroll property is equal to 1 (e.g. scrolled to top) if I try to get the char boundaries from line 12 (non new line char) that will return me null. So thanks again to adobe for not documenting such a messy problem in their functionality. And if someone from adobe want to say that: "Hey, we are the good guys.." - I say, that the word "good" is suitable only for god-like life forms and you ain't such ones. Took me a week to solve that bullsht. Cheers for adobe!

So now comes the next issue: how to get coordinates for a char on these bottom lines which is not scrolled to? Or should I always scroll in order to achieve that? If so - that sounds stupid as most stupid guy on the planet! Anyway I will be glad to recieve some answers... Otherwise how lame is this..?! I'm almost outraged.. Almost there..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Advocate ,
Feb 28, 2011

Copy link to clipboard

Copied

Don't know if this would work in your project, but here's one way of working around the problem:

import fl.controls.Button;

var tf:TextField= new TextField();
tf.multiline=tf.wordWrap=true;
tf.autoSize = TextFieldAutoSize.NONE;

tf.x=tf.y=50;
tf.width=150;
tf.height=100;
tf.background=true;
tf.text = "One\nTwo\nThree\nFour\nFive\nSix\nSeven\nEight\nNine\nTen\n";
addChild(tf);
//tf.scrollRect= new Rectangle(0,0,150,40);

var btn:Button = new Button();
btn.x=200;
btn.y=50;
btn.label = "Check";
addChild(btn);
btn.addEventListener(MouseEvent.CLICK, h);

function h(event:MouseEvent)
{
var saveHeight = tf.height; // save for a later reset
tf.autoSize = TextFieldAutoSize.LEFT;
tf.height=tf.height; // fixes a bug

for(var i:int= 0; i<tf.text.length; i++)
{
  var char:String = tf.text.substr(i,1);
  trace(i, ": " , (char=="\n"||char=="\r" ?"<CR>":char) ,": ", tf.getCharBoundaries(i))
}
tf.autoSize = TextFieldAutoSize.NONE;
tf.height =saveHeight; // reset to original height
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Feb 28, 2011

Copy link to clipboard

Copied

Nice workaround dude.. I didn't saw that one

Though, it's still not a real solution. What I was willing is to have a textfield on the stage and whatever the scroll or size of the textfield to be able to take the boundaries of a character. For instance, just to place the text field and then to get ANY character without stretching around the size of it

I solved the problem by always scrolling down when new message arrives, but.. that sucks really!

That's why I cant resize the text field, because then all goes wrong with the scroll and stuff.. I mean if the user had scrolled up a bit and later someone talks in the chat (let's say we talk about group chat), the temp height that I'll assign should be unknown.. althouth I got textHeight and I'm not sure if I can calculate the total height minus the scrolled size... But if I should do all of this there is no point to do it that way.. it's too cheap as performance and my time too.

Anyway I will appretiate more ideas about that and also I think the subject is interesting to all the guys who wants to create emoticons in their chats right

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
jord3t LATEST
Community Beginner ,
Jan 17, 2014

Copy link to clipboard

Copied

I wrestled with this problem for several hours.  I was getting a null rectangle and I fiunally figured out that the textfield original size was smaller than the expanded size after it autosized to fit more text.

everything outside of the original textField size returned a null.  I solved the problem by expanding the size of the textField on the stage so that it was big enough to fit all the dynamic text.

I usually dont use timeline animations but it was a client provided file.

thanks to Raymond for this loop that helped me figure out what was going on:

for(var i:int= 0; i<tf.text.length; i++)

{

  var char:String = tf.text.substr(i,1);

  trace(i, ": " , (char=="\n"||char=="\r" ?"<CR>":char) ,": ", tf.getCharBoundaries(i))

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...