In order to get the width of a text field you have created, you are supposed to use:
txt.getMeasuredWidth();
I was trying to add line breaks, EaselJS doesn't support html tags, so I used the \n line break, which works.
Problem? Now getting the measured width doesn't work (although height is fine). In fact, the more line breaks you add, the wider it thinks the text box is!
For myself, I am going to print out my longest line, and measure it's width, then replace it with the full text.
A diary about programming problems - to help me more easily learn from (and Google) past mistakes.
Showing posts with label line breaks. Show all posts
Showing posts with label line breaks. Show all posts
Wednesday, 15 May 2013
EaselJS: Text width
Friday, 6 August 2010
Line breaks
OK, so...
I am entering text in a flash text field, which gets sent to a mysql database. This later gets retrieved by php, and folded into a javascript function, so that another swf can use that data.
The problem is, if there are any line breaks in the initial text, then that ends up in the javascript function, and is seen as an error.
So to solve it, I will attempt to get the php file that takes the text out of the database, to convert that line break into something that the javascript function can stand, and that the swf can interpret.
Continuation -
Yeah, that worked. First I tried nl2br, which is supposed to put html linebreak tags where the line breaks are, although I din't see this effect. But this would have required me to make changes to my flash file.
So I used:
$lineBreaks = Array("\n","\r");
$iQuestion = ...get text from MySQL database
$oQuestion = str_replace($lineBreaks,'\u000d',$iQuestion);
$lineBreaks is an array of possible ways in which the line breaks may come down, I wasn't sure if this would differ depending on the user's operating system etc.
I am entering text in a flash text field, which gets sent to a mysql database. This later gets retrieved by php, and folded into a javascript function, so that another swf can use that data.
The problem is, if there are any line breaks in the initial text, then that ends up in the javascript function, and is seen as an error.
So to solve it, I will attempt to get the php file that takes the text out of the database, to convert that line break into something that the javascript function can stand, and that the swf can interpret.
Continuation -
Yeah, that worked. First I tried nl2br, which is supposed to put html linebreak tags where the line breaks are, although I din't see this effect. But this would have required me to make changes to my flash file.
So I used:
$lineBreaks = Array("\n","\r");
$iQuestion = ...get text from MySQL database
$oQuestion = str_replace($lineBreaks,'\u000d',$iQuestion);
$lineBreaks is an array of possible ways in which the line breaks may come down, I wasn't sure if this would differ depending on the user's operating system etc.
Labels:
as3,
Javascript,
line breaks,
mysql,
php,
str_replace
Thursday, 27 May 2010
HTML Notation Converter
Right, two text boxes on stage, one input:
This code was also output using it, and I put the ampersand and quote marks in, because it was great at converting html into html notation, but my actual html notation was getting converted back to html by the blog editor!
It doesn't recognise all linebreaks, but it will pick up on the proper ones, web text is a bit funny like that...
htmlinput.text = '';
htmlinput.addEventListener(Event.CHANGE,outputhtml);
var htmlCode:Array = ['<','>',"\r",'&','"'];
var htmlNotation:Array = ['<','>',"\n",'&','"'];
function outputhtml(evnt:Event):void {
htmloutput.text = "<pre>";
var str:String = htmlinput.text;
for(var i:uint = 0; i<str.length; i++) {
var char:String = str.charAt(i);
trace(char+' '+str.charCodeAt(i));
var ind:int = htmlCode.indexOf(char);
if(ind == -1) {
htmloutput.appendText(char);
}else{
htmloutput.appendText(htmlNotation[ind]);
}
}
htmloutput.appendText("</pre>");
}
This code was also output using it, and I put the ampersand and quote marks in, because it was great at converting html into html notation, but my actual html notation was getting converted back to html by the blog editor!
It doesn't recognise all linebreaks, but it will pick up on the proper ones, web text is a bit funny like that...
Subscribe to:
Posts (Atom)