2006/03/30 | 写了一个mc自己调整大小来显示动态文本的类
类别(Flash&AS2) | 评论(0) | 阅读(140) | 发表于 16:36
由于工作需要,今天写了这么一个类,目的是让MovieClip能根据里面的动态文本自己调整大小来适应这个文本,代码如下:
第一桢只要写:
//要显示的字符串
var str=
"gssssssgggggggggg666ssssssgggggggggg666ssssssgggggggggg666ssssssgggggggggg66";
new dynamicText(str, 50, 150);

dynamicText类里的代码如下:
class dynamicText {
  public function dynamicText(inputText:String, x, y:Number) {
    var background_mc = drawRectangle(_root, x, y, 0);
    var input_mc = drawRectangle(background_mc, 0, 0, 100);
    showText(background_mc, input_mc, inputText);
  }
  private function drawRectangle(root:MovieClip,x, y, alpha:Number):MovieClip {
    var background_mc = root.createEmptyMovieClip("rectangle", root.getNextHighestDepth());
    background_mc._x = x;
    background_mc._y = y;
    background_mc.beginFill(0xFF00FF, alpha);
    background_mc.lineStyle(0, 0xFF00FF, alpha);
    background_mc.lineTo(0, 0);
    background_mc.lineTo(100, 0);
    background_mc.lineTo(100, 100);
    background_mc.lineTo(0, 100);
    return background_mc;
  }
  private function showText(background_mc:MovieClip, input_mc:MovieClip, inputText:String) {
    var input_textField:TextField = background_mc.createTextField("input_txt", background_mc.getNextHighestDepth(), 0, 0, input_mc._width, input_mc._height);
    input_textField.type = "dynamic";
    input_textField.autoSize = true;
    input_textField.wordWrap = true;
    input_textField.multiline = true;
    input_textField.html = true;
    input_textField.htmlText = inputText;
    input_mc._width = input_textField.textWidth;
    input_mc._height = input_textField.textHeight;
  }
}
以后就直接调用这个类就行了。


0

评论Comments

日志分类
首页[116]
Flash&AS2[56]
FMS[3]
Flex&AS3[5]
Asp[5]
My Works[13]
My Life[34]