In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

できた forked from: switchだと改行判定できない。そんなもん?

rのときもnを入れることで解決
Get Adobe Flash player
by romatica 19 Apr 2011
    Embed
/**
 * Copyright romatica ( http://wonderfl.net/user/romatica )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uBlv
 */

// forked from romatica's switchだと改行判定できない。そんなもん?
package {
    import flash.display.Sprite; import flash.text.TextField;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
             var _tf : TextField = addChild(new TextField()) as TextField;
            _tf.text = "あ" + "\n" + "い" + "\r" + "う" + "\n\r" + "え"+ "\r"+ "\n"+"お";

            var _tf2 : TextField = addChild(new TextField()) as TextField;
            _tf2.x = 150;

            var _tf3 : TextField = addChild(new TextField()) as TextField;
            _tf3.x = 300;

            // ▼_tf.textを_tf2.textへ
            for (var i : int = 0; i < _tf.text.length; i++) {
                var str : String = _tf.text.charAt(i);
                if ("\n" == str || "\r" == str) {
                    _tf2.appendText("\n");
                }
                else if ("\n\r" == str ) {
                    _tf2.appendText("\n\r");
                }
                else {
                    _tf2.appendText(str);
                }
            }
            // ▼_tf.textを_tf3.textへ
            for (var j : int = 0; j < _tf.text.length; j++) {
                var str2 : String = _tf.text.charAt(j);
                switch(str2) {
                    case "\n":
                    case "\r":
                        _tf3.appendText("\n");
                        break;
                    case "\r\n":
                        _tf3.appendText("\n\r");
                        break;
                    default:
                        _tf3.appendText(str2);
                        break;
                }
            }

        }
    }
}