forked from: [Flash 10] Text Engine Demo
Flash 10 Text Engine Demo
* @author Yasu (clockmaker)
*
* Flash 10 の Text Engine を使うと
* 従来の Text Field のように拡大や移動時に
* ジャギらないという実験デモ
/**
* Copyright uwi ( http://wonderfl.net/user/uwi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uf6E
*/
// forked from clockmaker's [Flash 10] Text Engine Demo
/**
* Flash 10 Text Engine Demo
* @author Yasu (clockmaker)
*
* Flash 10 の Text Engine を使うと
* 従来の Text Field のように拡大や移動時に
* ジャギらないという実験デモ
*/
package {
import com.bit101.components.Label;
import flash.display.*;
import flash.system.*;
import flash.text.engine.*;
import flash.text.*;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.Elastic;
import org.libspark.betweenas3.tweens.ITween;
[SWF(frameRate=60)]
public class Main extends Sprite {
static private const MSG:String = "いいぜ\nてめえが何でも思い通りに出来るってなら\nまずはそのふざけた幻想をぶち殺す";
public function Main():void {
var textBox:Sprite = createTextBlock();
addChild(textBox);
textBox.x = stage.stageWidth / 2;
textBox.y = stage.stageHeight / 2 - 100;
var textField:Sprite = createTextField();
addChild(textField);
textField.x = stage.stageWidth / 2;
textField.y = stage.stageHeight / 2 + 100;
var tw:ITween = BetweenAS3.parallel(
BetweenAS3.tween(textBox, { scaleX:1, scaleY:1 }, { scaleX:0, scaleY:0 }, 4, Elastic.easeOut),
BetweenAS3.tween(textField, { scaleX:1, scaleY:1 }, { scaleX:0, scaleY:0 }, 4, Elastic.easeOut)
);
tw.stopOnComplete = false;
tw.play();
// 説明文(不要)
new Label(this, 180, 50, "Flash 10 Text Engine");
new Label(this, 200, 280, "Text Field");
}
private function createTextBlock():Sprite {
// Text Eingine については次の記事が参考になります
// http://level0.kayac.com/2008/12/textbox.php
// 設定値
var txtColor:uint = 0x000033;
var fontSize:uint = 24;
// フォント情報
var font:FontDescription = new FontDescription( "メイリオ,ヒラギノ角ゴ Pro W3,MS Pゴシック,_ゴシック,_等幅", FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.DEVICE, RenderingMode.NORMAL );
// 整列フォーマット情報
var format:ElementFormat = new ElementFormat( font, fontSize, txtColor );
format.locale = "ja";
// 段組
var textBlock :TextBlock = new TextBlock();
// 字の整列方向(縦書き)
textBlock.lineRotation = TextRotation.ROTATE_0;
textBlock.textJustifier = new EastAsianJustifier("ja", LineJustification.UNJUSTIFIED );
// 文字情報設定
textBlock.content = new TextElement( MSG, format );
var sp:Sprite = new Sprite();
// 実際に整形と配置
var i:uint = 0;
var textLine:TextLine = textBlock.createTextLine( null, 500 );
var zz : int = 0;
while (textLine) {
sp.addChild( textLine );
textLine.x = -textLine.width / 2;
textLine.rotationZ = zz;
textLine.rotationX = -60;
zz += 20;
textLine = textBlock.createTextLine(textLine, 500 );
}
return sp;
}
private function createTextField():Sprite {
var fontName:String = "_ゴシック";
if (Capabilities.os.indexOf("Vista") != -1) fontName = "メイリオ";
if (Capabilities.os.indexOf("XP") != -1) fontName = "MS Pゴシック";
if (Capabilities.os.indexOf("Mac") != -1) fontName = "ヒラギノ角ゴ Pro W3";
var format:TextFormat = new TextFormat(fontName, 24);
var text:TextField = new TextField();
text.width = 400;
text.text = MSG;
text.x = -text.width / 2;
text.y = -text.textHeight / 2;
text.autoSize = TextFieldAutoSize.CENTER;
text.setTextFormat(format);
var sp:Sprite = new Sprite;
sp.addChild(text);
text.rotationX = -60;
return sp;
}
}
}