import mx.transitions.Tween;
import mx.transitions.easing.*;
//メニュー(必要なメニューを設定)
var menuItem:Array = new Array("menu1", "menu2", "menu3", "menu4", "menu5", "menu6");
//メニューの数
var menuNum = menuItem.length;
//サブメニュー(必要に応じて数、メニュー名を設定)
var submenu:Array = new Array(["sub1", "sub2"],
["sub3", "sub4", "sub5", "sub6"],
["sub7", "sub8", "sub9"],
["sub10", "sub11", "sub12", "sub13", "sub14"],
["sub15", "sub16", "sub17"],
["sub18", "sub19", "sub20"]);
//バー、文字の色、サイズの初期設定
var frColor = 0xdddddd;
var bgColor = 0xeeeeee;
var txtColor = 0x333333;
var txtSize = 18;
var w = 110;
var h = 30;
var margin = 2;
//バーの配置、文字設定、ボタンとしての効果
for (i=1; i<=menuNum; i++) {
menu_mc = this.createEmptyMovieClip("menu"+i, i);
menu_mc.createTextField("tf",i,5,2.5,w-5,h-5);
menu_mc.tf.text = menuItem[i-1];
menu_mc._x = margin+(w+margin)*(i-1);
menu_mc._y = margin;
menu_mc.num = i;
fillRec(menu_mc);
tfFormat(menu_mc);
menu_mc.onRollOver = pulldown;
}
//メニューバーロールオーバーでプルダウンメニューを表示
function pulldown() {
n = this.num;
subNum = submenu[n-1].length;
//全サブメニューを格納するMC
submenuBox = _root.createEmptyMovieClip("subMenu"+n, -100+n);
submenuBox._x = this._x;
submenuBox._y = this._y;
for (i=1; i<=subNum; i++) {
//サブメニューを格納するMCを作り、そこにテキストフィールドを入れる
sub_mc = submenuBox.createEmptyMovieClip("sub"+i, -50+i);
sub_mc.createTextField("tf",-50+i,5,2.5,w-5,h-5);
sub_mc.tf.text = submenu[n-1][i-1];
fillRec(sub_mc);
tfFormat(sub_mc);
sub_mc._y = y0=h+margin;
targety = y0+(i-1)*(h+margin);
new Tween(sub_mc, "_y", Regular.easeOut, y0, targety, 0.5, true);
sub_mc.subNo = i;
sub_mc.onRollOver = rollov;
sub_mc.onRollOut = rollot;
sub_mc.onRelease = jump;
}
//メニューバーロールアウトでサブメニューを非表示に
this.onRollOut = removeMc;
//submenuBoxからマウスが外れたらサブメニューをプルアップする
submenuBox.onEnterFrame = pullup;
}
//sub_mcのロールオーバー、ロールアウト
function rollov() {
rollover = true;
frColor = 0x3300ff;
bgColor = 0x999999;
txtColor = 0xffffff;
fillRec(this);
tfFormat(this);
}
function rollot() {
frColor = 0xdddddd;
bgColor = 0xeeeeee;
fillRec(this);
txtColor = 0x333333;
tfFormat(this);
}
//メニューバーロールアウトでサブメニューを非表示に
function removeMc() {
if (!submenuBox.hitTest(_xmouse, _ymouse, true)) {
submenuBox._visible = false;
}
}
//submenuBoxロールアウトでサブメニューをたたむ
function pullup() {
if (_xmouse<this._x || _xmouse>this._x+w || _ymouse>this._y+h*(subNum+1)) {
for (i=1; i<=subNum; i++) {
sub = this["sub"+i];
sub._y += (0-sub._y)/3;
if (this["sub"+subNum]._y<0.1) {
sub._y = 0;
delete this.onEnterFrame;
}
}
}
}
//sub_mcのリリースでリンク先に
function jump() {
submenuBox._visible = false;
targetURL = url[n-1][this.subNo-1];
getURL(targetURL);
}
//リンク先の登録
var url:Array = new Array(["http://www.yahoo.co.jp", "http://flashiroha.com"],
["/hogehoge.html", "http;//hoge.com", "", ""],
["", "", ""],
["", "", "", "", "", ""],
["", "", ""],
["", "", ""]);
//矩形の描画・塗り
function fillRec(mc) {
mc.clear();
mc.lineStyle("2",frColor);
mc.beginFill(bgColor);
mc.moveTo(0,0);
mc.lineTo(w,0);
mc.lineTo(w,h);
mc.lineTo(0,h);
mc.lineTo(0,0);
mc.endFill();
}
//文字のスタイル
function tfFormat(mc) {
var menuFormat = new TextFormat();
with (menuFormat) {
size = txtSize;
color = txtColor;
align = "center";
bold = true;
}
mc.tf.setTextFormat(menuFormat);
} |