vertical label

/** * Author: Lior Gonnen * Date: 17-Nov-2007 * * Please visit: http://liorgonnen.blogspot.com */ package org.pace2020.appbox.components { import flash.display.BitmapData; import flash.display.DisplayObject; import mx.controls.Label; /** * Use this Label class instead of the standard mx.controls.Label to allow text rotation * (using the 'rotation' property) without using embedded fonts! */ public class RotatableLabel extends mx.controls.Label { private var _labelBitmap : BitmapData = null; /** * updateDisplayList is used to draw a rotated bitmap of the label */ protected override function updateDisplayList(unscaledWidth : Number, unscaledHeight : Number) : void { super.updateDisplayList(unscaledWidth, unscaledHeight); // 1. Make sure that the width and the height are greater than zero, otherwise we have nothing to do. // 2. Make sure rotation is different than zero, otherwise the label will show normally // 3. Draw the label into a bitmap, and then draw it onto the label, since the label is rotated // the bitmap will be displayed rotated as well. Nice, ha? ;-) if (unscaledWidth > 0 && unscaledHeight > 0 && rotation != 0) { graphics.clear(); _labelBitmap = getBitmapData(this); if (_labelBitmap) { graphics.beginBitmapFill(_labelBitmap); graphics.drawRect(0, 0, unscaledWidth, unscaledHeight); graphics.endFill(); } } } /** * Create a bitmap from a displayObject * @param target The displayObject to draw * @return The drawn bitmap */ public static function getBitmapData(target : DisplayObject) : BitmapData { var bd : BitmapData = new BitmapData(target.width, target.height, true, 0.0); bd.draw(target); return bd; } } }

你可能感兴趣的:(Flash)