开发者

How to skew a Textfield in Actionscript 3.0?

How can I skew a Textfield in order to set a ascending space for each line. Following image should illustrate my inten开发者_C百科tion:


Got it: adobe

public class TextBlock_createTextLineExample extends Sprite {

    public function TextBlock_createTextLineExample():void {

        var str:String = "I am a TextElement, created from a String and assigned " +
        "to the content property of a TextBlock. The createTextLine() method " +
        "then created these lines, 300 pixels wide, for display." ;

        var fontDescription:FontDescription = new FontDescription("Arial");
        var format:ElementFormat = new ElementFormat(fontDescription);
        format.fontSize = 16;
        var textElement:TextElement = new TextElement(str, format); 
        var textBlock:TextBlock = new TextBlock();
        textBlock.content = textElement; 
        createLines(textBlock); 
    }

    private function createLines(textBlock:TextBlock):void 
    {            
        var lineWidth:Number = 300;
        var xPos:Number = 15.0;
        var yPos:Number = 20.0;

        var textLine:TextLine = textBlock.createTextLine (null, lineWidth);
        while (textLine)
        {
            //increase textLine every Line 10 px to get an offset 
            textLine.x += 10
            textLine.y = yPos;
            yPos += textLine.height + 2;
            addChild (textLine);
            textLine = textBlock.createTextLine (textLine, lineWidth);
        }
    }
}

}


private static const _DEG2RAD:Number = Math.PI/180;

public static function skew(target:DisplayObject, skewXDegree:Number, skewYDegree:Number):void
{
    var m:Matrix = target.transform.matrix.clone();
    m.b = Math.tan(skewYDegree*_DEG2RAD);
    m.c = Math.tan(skewXDegree*_DEG2RAD);
    target.transform.matrix = m;
}   

public static function skewY(target:DisplayObject, skewDegree:Number):void
{
    var m:Matrix = target.transform.matrix.clone();
    m.b = Math.tan(skewDegree*_DEG2RAD);
    target.transform.matrix = m;
}       

public static function skewX(target:DisplayObject, skewDegree:Number):void
{
    var m:Matrix = target.transform.matrix.clone();
    m.c = Math.tan(skewDegree*_DEG2RAD);
    target.transform.matrix = m;
}   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜