Показать сообщение отдельно
Старый 24.04.2008, 11:00
codecast вне форума Посмотреть профиль Найти все сообщения от codecast
  № 3  
Ответить с цитированием
codecast
Banned

Регистрация: Mar 2008
Сообщений: 24
мм...
autoSize не катит, так как необходимо еще центрирование по высоте.
Но я уже нашел решение silin'а:
Код:
function getTextRect(tf:TextField):Rectangle {
	
	var tmpBmp:BitmapData = new BitmapData(tf.width, tf.height, true, 0x00000000);
	tmpBmp.draw(tf);
	var result:Rectangle = tmpBmp.getColorBoundsRect(0xFFFFFFFF, 0x00000000, false);
	tmpBmp.dispose();
	
	return result;
}
и ваше решение для AS2 тоже:
Код:
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();
такие адские шаманства с бубном надо класть в faq!