开发者

flash textfiled line .....for help

package {
    import flash.display.Sprite;
    import flash.text.TextField;

    public class test extends Sprite
    {
        private var _textFiled:TextField;
        public function test()
        {
            _textFiled = new TextField();
            _textFiled.text = ".  2011年8月15日晚,据传<a href='http://www.google.com.hk'>Google</a> 将以 <font size = '12'>40 </font> 美元现金每股,总价 125 亿美元,收购摩托罗拉移动";
            _textFiled.width = 300;
            _textFiled.wordWrap = true;
            _textFiled.multiline = true;
            var st:String = "";
            for (var i:int = 0; i < _textFiled.numLines; i++) {
                var s:String = _textFiled.getLineText(i) + "\n    ";
                st += s;
            }
            _textFiled = new TextField();
            _textFiled.width = 300;
            _textFiled.wordWrap = true;
            _textFiled.multiline = true;
            _textFiled.htmlText = st;

            addChild(_textFiled);
        }
    }
}

Now I have such a demand, I want to use textfiled reality a text, the text contains the HTML code, I think in line with a TAB after, I know textfiled in one of the getlineText method, and then back to add a "\ t"

var strText:string = "";
for(var i:int =9开发者_如何学C;i<textfile.numLine;i++) {

  var str:String = textfiled.getlineText(i) + "\t";
  strText += str;
}
textfile.htmlText = strText ;

But this can only get text, HTML code filtering, I come from China, first time in here to ask questions, thank everybody.


Tabs won't be shown in html. If multiple spaces are ok, insert as many &nbsp; as needed. If tabs are needed in the middle of a line, it would be necessary to calculate how many spaces are actually needed. In that case, when using flash, it would probably be easier to create multiple TextFields, one for each column.


I'm not sure if this is what you're asking, but if you don't want to lose the HTML formatting, you need to get the text using _textFiled.htmlText. Then if you want to read it line by line, it's quite tricky because both <p> and <br> are going to create new lines. Depending on your input, maybe you can just split the string by <br> tags:

var lines:Array = _textFiled.htmlText.split("<br>");
for(var i:int =9;i<lines.length;i++) {

  var str:String = lines[i] + "\t";
  strText += str;
}

But again, it depends on the input - if it's user generated, there's a lot more parsing you need to do. If not, and you know how the HTML is going to be formatted, it's much easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜