var string:String = new String(); string = "●本节教学的重点是有理数的概念.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点."; putWord(getHeight(string)+14,string); function getHeight(string:String):Number { var MenuTxt_tmp:TextField = new TextField(); var MenuTxt_TextFormat:TextFormat = new TextFormat(); MenuTxt_tmp.name = "toom"; MenuTxt_tmp.width = 160; MenuTxt_tmp.text = string; MenuTxt_tmp.multiline = true; MenuTxt_tmp.wordWrap = true;//自动换行 MenuTxt_TextFormat.leading = 7; MenuTxt_TextFormat.font = "宋体"; MenuTxt_TextFormat.size = 14; MenuTxt_tmp.setTextFormat(MenuTxt_TextFormat); return MenuTxt_tmp.textHeight; } function putWord(wordHeight:Number,string:String):void { www.2cto.com var MenuTxt_tmp:TextField = new TextField(); var MenuTxt_TextFormat:TextFormat = new TextFormat(); MenuTxt_tmp.name = "tom"; MenuTxt_tmp.x = 100; MenuTxt_tmp.y = 100; MenuTxt_tmp.width = 160; MenuTxt_tmp.height = wordHeight; MenuTxt_tmp.text = string; MenuTxt_tmp.multiline = true; MenuTxt_tmp.wordWrap = true; MenuTxt_TextFormat.leading = 7; MenuTxt_TextFormat.font = "宋体"; MenuTxt_TextFormat.size = 14; MenuTxt_tmp.setTextFormat(MenuTxt_TextFormat); addChild(MenuTxt_tmp); } 实际项目中用的代码。注意把字体的高度加上来 [plain] var string:String = new String(); string = "●本节教学的重点是有理数的概念.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点."; var MenuTxt_tmp:TextField = new TextField(); var MenuTxt_TextFormat:TextFormat = new TextFormat(); MenuTxt_tmp.name = "tom"; MenuTxt_tmp.x = 100; MenuTxt_tmp.y = 100; MenuTxt_tmp.width = 160; MenuTxt_tmp.text = string; MenuTxt_tmp.multiline = true; MenuTxt_tmp.wordWrap = true; MenuTxt_TextFormat.leading = 7; MenuTxt_TextFormat.font = "宋体"; MenuTxt_TextFormat.size = 14; MenuTxt_tmp.setTextFormat(MenuTxt_TextFormat); MenuTxt_tmp.height = MenuTxt_tmp.textHeight+14;//注意把字体的size加上来 addChild(MenuTxt_tmp);
|