In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

テキストボタンを作ってみたよ

...
@author axcel-work
Get Adobe Flash player
by axcelwork 01 Apr 2009
package  {
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author axcel-work
	 */
	public class Main extends Sprite {
		
		public function Main() {
			var margin:int = 20;
			
			var aryText:Array = new Array( "Top", "About", "Contact", "" );
			var aryLink:Array = new Array( "http://www.shift-style.org/blog/",
			"http://www.shift-style.org/blog/?page_id=38",
			"mailTo:axcelwork@gmail.com");
			var aryWindow:Array = new Array( "_blank", "_blank", "_blank" );
			
			var prevNum:Number = 0;
			var setFlg:Boolean = false;
			
			for ( var i:int = 0; i < aryLink.length; i++ ) {
				/* インスタンスの作成 */
				var btnBox:Button_Text_Boder = new Button_Text_Boder( aryText[i], aryLink[i], aryWindow[i], margin );
				
				if ( setFlg ) {
					btnBox.x = prevNum - ( 1 * i );
					prevNum += btnBox.width;
				}
				else {
					btnBox.x = 0;
					prevNum = btnBox.width;
				}
				
				setFlg = true;
				
				///* 表示 */
				addChild( btnBox );
			}
			
		}
		
	}
	
}


import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
	
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
	
/**
 * ...
 * @author axcel-work
 */
class Button_Text_Boder extends MovieClip {
	private var txtLink:TextField;
	private var txtF:TextFormat;
		
	private var sprBorder:Sprite;
		
	private var _LINK:String;
	private var _WINDOW:String;
		
	public function Button_Text_Boder( contents:String = null, link:String = null, window:String = null, margin:int = 0 ):void{
		txtLink = new TextField();
		txtLink.selectable = false;
		txtLink.autoSize = "left";
		txtLink.mouseEnabled = false;
		txtLink.x = margin;
			
		txtF = new TextFormat();
		txtF.underline = false;
		txtLink.defaultTextFormat = txtF;
			
		txtLink.text = contents;
			
		this.addChild( txtLink );
			
		/* Boderの設定 */
		sprBorder = new Sprite();
		draw( sprBorder, 0xCCCCCC, 1, txtLink.height );
		this.addChild( sprBorder );
			
		sprBorder = new Sprite();
		draw( sprBorder, 0xCCCCCC, 1, txtLink.height );
		sprBorder.x = txtLink.width + txtLink.x + margin;
		this.addChild( sprBorder );
			
		/* イベント定義一式 */
		this.addEventListener( MouseEvent.MOUSE_OVER, btnOverHandler );
		this.addEventListener( MouseEvent.MOUSE_OUT, btnOutHandler );
		this.addEventListener( MouseEvent.CLICK, btnClickHandler );
		this._LINK = link;
		this._WINDOW = window;
		
		/* マウスカーソルを指印に */
		this.buttonMode = true;
	}
		
	/*===============================================
	 * イベントハンドラ:オーバー、アウト、クリック、ダブルクリック
	 */
	private function btnOverHandler( evt:MouseEvent ):void {
		txtF.underline = true;
		txtLink.setTextFormat( txtF );
	}
	private function btnOutHandler( evt:MouseEvent ):void {
		txtF.underline = false;
		txtLink.setTextFormat( txtF );
	}
	private function btnClickHandler ( evt:MouseEvent ):void {
		navigateToURL( new URLRequest( evt.target._LINK ), evt.target._WINDOW );
	}
		
	/*===============================================*//*
	 * メソッド:色を塗り替える
	 * @param --> target [Sprite]
	 * @param --> color [int]
	 * @param --> size [int]
	 */
	private function draw( target:Sprite, color:int, width:int, height:int ):void {
		target.graphics.clear();
		target.graphics.beginFill( color, 1 );
		target.graphics.drawRect( 0, 0, width, height );
		target.graphics.endFill();
	}
	
}