flash on 2009-12-30

by buccchi
♥0 | Line 117 | Modified 2009-12-31 11:04:56 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
	import flash.text.TextField;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldType;
	
	
    public class FlashTest extends Sprite {
    	 	private const COLOR_PINK:Number = 0xFF3366;
		private var _loader:MyFontLoader;
		
        public function FlashTest() {
			_loader = new MyFontLoader();
			init();
			/*_loader.addEventListener(Event.COMPLETE,function(e:Event):void{
				init();
            });*/
		}
		
		private function init():void {
			
			//矩形確認
			/*var s:Sprite = new Sprite();
			s.graphics.beginFill(0xFF0000, .5);
			s.graphics.drawRect(0, 0, 10, 10);
			addChild(s);*/
			
		
			
			//var test:TextField = _loader.test("名前を入力してください");
			//addChild(test);
			//test.y = 50;
			
			
			
			x = 100;
			y = 100;
			var tfWord:TextField = _loader.createDTF(COLOR_PINK);
			addChild(tfWord);
			
			
			var submit:Sprite = new Sprite();
			submit.graphics.beginFill(COLOR_PINK, 1);
			submit.graphics.drawRect(0, 0 , 80 , 19);
			submit.x = 202;
			var t:TextField = _loader.createTF("入力", 0xFFFFFF, 14);
			
			var myText:MyText = new MyText(t);
			myText.x = submit.width/2 - myText.w/2;
			myText.y = submit.height/2 - myText.h/2;
			trace(myText.w, myText.h);
			submit.addChild(myText);
			addChild(submit);
			
			submit.buttonMode = true;
			submit.mouseChildren = false;
			submit.addEventListener(MouseEvent.ROLL_OVER, overHandler);
			submit.addEventListener(MouseEvent.ROLL_OUT, outHandler);
			
			
			//rotation = 10;
		}
		private function overHandler(e:MouseEvent):void {
			e.target.alpha = .6;
		}
		private function outHandler(e:MouseEvent):void {
			e.target.alpha = 1;
		}
    }
}





import flash.events.Event;
import flash.events.EventDispatcher;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldType;
import flash.system.Security;

class MyFontLoader extends EventDispatcher {
	
	
	
	private var _myFont:Font;
	
	public function MyFontLoader() {
		/*Security.loadPolicyFile("http://7980.oui-imja.com/wonderfl/font/crossdomain.xml"); 
		//外部フォントの読み込み
		var req :URLRequest = new URLRequest("http://7980.oui-imja.com/wonderfl/font/hiragino_mincho.swf");
		var loader:Loader = new Loader();
		var context :LoaderContext = new LoaderContext();
		context.applicationDomain = ApplicationDomain.currentDomain;
		loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadCompleteHandler );
		loader.load( req, context );*/
	}
	
	/*private function onLoadCompleteHandler(e:Event):void {
		var MyFont:Class = e.target.applicationDomain.getDefinition("HiraginoMincho") as Class;
      	Font.registerFont(MyFont);
		_myFont = new MyFont();
		dispatchEvent(new Event(Event.COMPLETE));
	}*/
	
	public function createTF(str:String, myColor:Number=0xFF0000, size:Number=24):TextField {
		var fmt:TextFormat = new TextFormat();
		fmt.font = '_明朝';
		fmt.bold = true;
		fmt.letterSpacing = -.5;
		fmt.rightMargin = 1;
		fmt.color = myColor;
		fmt.size = size;
		fmt.kerning = true;
		
		var tf:TextField = new TextField();
		tf.text = str;
		tf.autoSize = "left";
		//tf.selectable = false;
		tf.setTextFormat(fmt);
		//tf.defaultTextFormat = fmt;
		//tf.embedFonts = true;
		return tf;
	}
	
	public function createDTF(myColor:Number):TextField {
		var fmt:TextFormat = new TextFormat();
		fmt.font = '_明朝';
		fmt.bold = true;
		fmt.color = myColor;
		fmt.size = 14;
		
		
		var tf:TextField = new TextField();
		tf.width = 200;
		tf.height = 18;
		tf.type = TextFieldType.INPUT; 
		tf.border = true;
		tf.borderColor = myColor;
		//tf.setTextFormat(fmt);
		tf.defaultTextFormat = fmt;
		//tf.autoSize = "left";
		//tf.embedFonts = true;
		return tf;
	}
}
	
	
	
	
	
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.display.Sprite;
import flash.display.Bitmap;

class MyText extends Sprite {
	private var _tf:TextField;
	private var _bound:Rectangle;
	
	public function get w():Number {
		return _bound.width;
	}
	public function get h():Number {
		return _bound.height;
	}
	
	public function MyText(tf:TextField) {
		_tf = tf;
		
		var bmd:BitmapData = new BitmapData(_tf.width, _tf.height, true, 0xFF000000);
		bmd.draw(_tf);
		_bound = bmd.getColorBoundsRect(0xFFFFFFFF, 0xFF000000, false);
		bmd.dispose();
		
		addChild(_tf);
		
		
		
		
		_tf.x = -_bound.x;
		_tf.y = -_bound.y;
	}
}

Forked