TextField converts LF to CR
This is why you fail to find "\n" in the text of TextFields...
♥0 |
Line 41 |
Modified 2010-12-21 21:51:53 |
MIT License
archived:2017-03-20 13:36:33
ActionScript3 source code
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vMPA
*/
package {
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private static const CR:String = '\r';
private static const LF:String = '\n';
public function FlashTest() {
var dumper:TextField = addChild(new TextField) as TextField;
dumper.defaultTextFormat = new TextFormat('_typewriter');
dumper.width = 415; dumper.height = 465; dumper.x = 50;
var tfYPos:int = 0;
var numbers:Array = "123".split("");
([
numbers.join(CR), // CR
numbers.join(LF), // LF
numbers.join(CR+LF) // CR+LF
]).forEach(function (str:String, i:int, arr:Array):void {
var tf:TextField = new TextField;
tf.y = tfYPos;
hexDump(str);
dumper.appendText('-> ');
tf.text = str;
hexDump(tf.text);
tf.height = tf.textHeight + 4;
tfYPos += tf.height;
addChild(tf);
});
function hexDump(str:String):void {
str.split('').forEach(function(char:String, ...rest):void {
dumper.appendText(toHex(char.charCodeAt(0)) + " ");
});
dumper.appendText('\n');
}
function toHex(intVal:int):String {
var hex:String = intVal.toString(16);
return (hex.length == 1) ? "0" + hex : hex;
}
}
}
}