- ムービークリップを作成し、「button1」という名前を付けます
- そのムービークリップを必要な数だけ複製し、「button2」「button3」などの名前を付けます
- 別の MovieClip を作成し、「main」という名前を付けてレイヤー 1 に配置し、「Main」を instanceName として追加します。
- 「メイン」ムービークリップ内に 2 つのボタンを追加し、「ボタン 1」と「ボタン 2」をそれぞれインスタンス名として追加します。
- メイン MovieClip の Class ファイルを作成する
- 次のコードをコピーしてクラスとして貼り付けます
または、examples.zip をダウンロードして参照してください http://www.comvos.net/downloads/examples.zip
class main extends MovieClip
{
function main() { super(); }
function onLoad()
{
this.ControlMyMC();
}
function ControlMyMC()
{
//Turn OFF the HandCursor of Main MC
this.useHandCursor = false;
this.onRollOver = function()
{
this["AnimatedBG"].gotoAndPlay(2);
trace("RollOver Main MC");
}
this.onRollOut = function()
{
this["AnimatedBG"].gotoAndPlay(21);
trace("RollOut Main MC");
}
var ButtonInstanceNames:Array = [
"Button1",
"Button2"
];
for(var i:Number = 0; i < ButtonInstanceNames.length; i++)
{
this[ButtonInstanceNames[i]].onEnterFrame = function()
{
if (this.hitTest(_root._xmouse, _root._ymouse, true))
{
//ROLL OVER BUTTON
if (!this.isRollOver)
{
this.isRollOver = true;
trace("RollOver " + _name);
}
}
else
{
//ROLL OUT BUTTON
if (this.isRollOver)
{
this.isRollOver = false;
trace("RollOut " + _name);
}
}
}
//ON RELEASE ---(if you want to use onPress .... just replace the onMouseUp wit onMouseDown
this[ButtonInstanceNames[i]].onMouseUp = function()
{
if (this.hitTest(_root._xmouse, _root._ymouse, true))
{
switch (_name)
{
case "Button1": trace("You Clicked on Button 1 ... replace me with ---> this.getURL(\"page1.html\");"); break;
case "Button2": trace("You Clicked on Button 2 ... replace me with ---> this.getURL(\"page2.html\");"); break;
//example
case "Button3": this.getURL("name.html"); break;
default: trace("aa"); break;
}
}
}
}
}
}