テキストの回転

by termat
♥0 | Line 70 | Modified 2010-02-07 01:07:35 | MIT License
play

ActionScript3 source code

/**
 * Copyright termat ( http://wonderfl.net/user/termat )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oaOd
 */

package
{
	import com.bit101.components.Text;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;

	[SWF(framerate="30",width="500",height="500",backgroundColor="0x000000")]
	public class Practice20 extends Sprite{
		private var text:TextImage;
		private var tf:TextFormat;
		
		public function Practice20(){
			tf = new TextFormat();
			tf.size = 36;
			tf.bold = true;
			tf.color = 0x0000ff;
			text = new TextImage("Hello world.こんにちは!", tf, 0xffffff);
			text.update();
			text.x = 250;
			text.y = 250;
			this.addChild(text);
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMove);
			stage.addEventListener(Event.ENTER_FRAME,update);
		}
		
		private function update(e:Event):void {
			text.rotationZ += 10;
		}
		
		private function mouseMove(e:MouseEvent):void {
			var dist:Number = Math.sqrt(Math.pow(e.stageX - text.x, 2) + Math.pow(e.stageY - text.y, 2));
			if (dist < 4) dist = 4;
			tf.size = dist;
			text.update();
		}
	}
}
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Bitmap;
import flash.display.BitmapData;
class TextImage extends MovieClip {
	private var backGround:uint;
	private var str:String;
	private var format:TextFormat;
	
	public function TextImage(s:String, f:TextFormat, c:uint):void {
		str = s;
		backGround = c;
		format = f;
	}
	
	public function update():void {
		while (this.numChildren > 0) this.removeChildAt(this.numChildren - 1);
		var text:TextField = new TextField();
		text.defaultTextFormat = format;
		text.text = str;
		text.width = text.textWidth;
		text.height = text.textHeight;
		var mc_tmp:MovieClip = new MovieClip();
		mc_tmp.addChild(text);
		var bd:BitmapData = new BitmapData(text.textWidth + 2, text.textHeight + 2);
		bd.fillRect(bd.rect,backGround);
		bd.lock();
		bd.draw(mc_tmp);
		bd.unlock();
		var mc:MovieClip = new MovieClip();
		mc.addChild(new Bitmap(bd, "auto", true));
		mc.x = -text.textWidth/2;
		mc.y = -text.textHeight/2;
		addChild(mc);
	}
}