- 创建一个 MovieClip 并将其命名为“button1”
- 复制该 MovieClip 尽可能多的按钮,并将名称命名为“button2”“button3”等
- 创建另一个 MovieClip 并将其命名为“main”,将其放入您的第 1 层,并将“Main”添加为 instanceName
- 在“Main”MovieClip 中添加两个按钮,并分别添加“Button1”和“Button2”作为 Instancename
- 为主影片剪辑创建一个类文件
- 将以下代码复制粘贴为类
或者下载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;
}
}
}
}
}
}