AS3 Convert TextField LineBreaks to CRLF for Display as Plain Text (Notepad) on Windows


/ Published in: ActionScript 3
Save to your folder(s)

Linebreaks differ between Flash TextField and a plain text file like Notepad. In this example we convert the html linebreaks in Flash to \r\n


Copy this code and paste it in your HTML
  1. var originalStr:String = "<p>Each<br>word<br>should<br>be<br>on<br>a<br>new<br>line.</p><p>\tThis line should be tabbed.</p><p>But this line shouldn't be tabbed.</p><p><li>Bullet points don't work though</li><li>Bullet points don't work though</li><li>Bullet points don't work though</li></p><p>Paste into Notepad to view the results!</p>";
  2.  
  3. var textfieldStr:String = unescape(originalStr);
  4.  
  5. var tf:TextField = new TextField();
  6. tf.multiline = true;
  7. tf.width = stage.stageWidth;
  8. tf.height = stage.stageHeight;
  9. addChild(tf);
  10. tf.htmlText = textfieldStr;
  11.  
  12. var clipboardForNotepadStr:String = unescape(tf.text.replace(/\r/g, '
  13. '));
  14. System.setClipboard(clipboardForNotepadStr);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.