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

by ProjectNya forked from switchだと改行判定できない。そんなもん? (diff: 14)
♥0 | Line 44 | Modified 2011-04-19 16:05:57 | MIT License
play

ActionScript3 source code

/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nK7f
 */

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

            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 (LF == str || CR == str) {
                    _tf2.appendText(LF);
                }
                else if (CR+LF == str ) {
                    _tf2.appendText(CR+LF);
                }
                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 LF:
                        _tf3.appendText(LF);
                        break;
                    case CR:
                        _tf3.appendText(CR);
                        break;
                    case CR+LF:
                        _tf3.appendText(CR+LF);
                        break;
                    default:
                        _tf3.appendText(str2);
                        break;
                }
            }

        }
    }
}