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 intWidth:int = 50;
                var intHeight:int = 50
                
                var aryLink:Array = new Array( "http://www.yahoo.co.jp/",
                "http://www.shift-style.org/blog/",
                "http://axcelwork.tumblr.com/");
                
                var aryWindow:Array = new Array( "_self", "_blank", "_self" );
                
                for ( var i:int = 0; i < aryLink.length; i++ ) {
                    /* インスタンスの作成 */
                    var btnBox:Button_Rect_HighLight = new Button_Rect_HighLight( intWidth, intHeight, aryLink[i], aryWindow[i] );
                    /* 位置の設定 */
                    btnBox.y = ( intHeight + 20 ) * i;
                    
                    /* 表示 */
                    addChild( btnBox );
                }	
            }
    }
	
}

import flash.display.MovieClip;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
	
/**
 * ...
 * @author axcel-work
 */
class Button_Rect_HighLight extends MovieClip {
    private var sprHighLight:MovieClip;
    
    private var  widthSize:int;
    private var  heightSize:int;
    private var _LINK:String;
    private var _WINDOW:String;
    
    public function Button_Rect_HighLight( width:int = 0, height:int = 0, link:String = null, window:String = null ):void{
        /* 幅と高さを代入 */
        widthSize = width;
        heightSize = height;
        
        /* 塗りつぶす */
        draw( this, 0xFF0000, widthSize, heightSize );
        
        /* イベント定義一式 */
        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;
			
	/* ハイライト用のスプライト作成 */
	sprHighLight = new MovieClip();
	draw( sprHighLight, 0xFFFFFF, widthSize, heightSize );
	sprHighLight.alpha = 0.5;
	sprHighLight.mouseEnabled = false;
    }
		
    /*
     * イベントハンドラ:オーバー、アウト、クリック、クリック
     */
    private function btnOverHandler( evt:MouseEvent ):void {
	evt.target.addChild( sprHighLight );
    }
    private function btnOutHandler( evt:MouseEvent ):void {
        evt.target.removeChild( sprHighLight );
    }
    private function btnClickHandler ( evt:MouseEvent ):void {
        navigateToURL( new URLRequest( evt.target._LINK ), evt.target._WINDOW );
    }
		
		
    /*
     * メソッド:色を塗り替える
     */
    private function draw( target:MovieClip, 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();
    }
		
}