Показать сообщение отдельно
Старый 06.07.2007, 07:47
etc вне форума Посмотреть профиль Найти все сообщения от etc
  № 60  
Ответить с цитированием
etc
Et cetera
 
Аватар для etc

Регистрация: Sep 2002
Сообщений: 30,787
Код:
import flash.geom.*;
import flash.display.BitmapData;
getTextBounds = function(txt) {
	var mc = txt._parent.createEmptyMovieClip('__textBounds_mc',-3288);
	var t = mc.createTextField('txt',0,0,0,100,100);
	t.setNewTextFormat(txt.getTextFormat());
	t.embedFonts = txt.embedFonts;
	t.html = txt.html;
	t.htmlText = txt.htmlText;
	t._width = txt._width;
	t._height = txt._height;
	txt = t;
	var xs = txt._xscale;
	var ys = txt._yscale;
	var scale = 20;
	var maxXScale = 2800/txt._width;
	var maxYScale = 2800/txt._height;
	if (maxXScale < scale) {
		scale = maxXScale;
	}
	if (maxYScale < scale) {
		scale = maxYScale;
	}
	txt._xscale = xs*scale;
	txt._yscale = ys*scale;
	var bmp = new BitmapData(mc._width,mc._height,true,0);
	bmp.draw(mc);
	bmp.colorTransform(bmp.rectangle,new ColorTransform(1,1,1,1,0,0,0,255));
	var rect = bmp.getColorBoundsRect(0xFF000000,0x00000000, false);
	bmp.fillRect(rect,0x80FFFF00);
	rect.x /= scale;
	rect.y /= scale;
	rect.width /= scale;
	rect.height /= scale;
	txt._xscale = xs;
	txt._yscale = ys;
	bmp.dispose();
	mc.swapDepths(6550);
	mc.removeMovieClip();
	return rect;
}
rect = getTextBounds(txt);
beginFill(0xFF0000, 30);
moveTo(txt._x+rect.x,txt._y+rect.y);
lineTo(txt._x+rect.x+rect.width,txt._y+rect.y);
lineTo(txt._x+rect.x+rect.width,txt._y+rect.y+rect.height);
lineTo(txt._x+rect.x,txt._y+rect.y+rect.height);
endFill();