由于某些原因,这段代码不想工作;它应该是使用"数组"的一个方便的替代方案。对于导航按钮,单击一个按钮可以从其余按钮中删除单击状态 -
nav_mc.buttonMode=true;
nav_mc.addEventListener(MouseEvent.MOUSE_OVER, navOver);
nav_mc.addEventListener(MouseEvent.MOUSE_OUT, navOut);
nav_mc.addEventListener(MouseEvent.CLICK, navClick);
nav_mc.nav1_mc.mouseChildren=false;
nav_mc.nav2_mc.mouseChildren=false;
nav_mc.nav3_mc.mouseChildren=false;
nav_mc.nav4_mc.mouseChildren=false;
var currentNav:MovieClip;
function navOver(e:MouseEvent):void {
var navItem:MovieClip=e.target as MovieClip;
trace(navItem.name);
if (navItem!=currentNav) {
navItem.gotoAndStop(2);
}
}
function navOut(e:MouseEvent):void {
var navItem:MovieClip=e.target as MovieClip;
if (navItem!=currentNav) {
navItem.gotoAndStop(1);
}
}
function navClick(e:MouseEvent):void {
var navItem:MovieClip=e.target as MovieClip;
if (currentNav!=null) {
navItem.gotoAndStop(1);
}
currentNav=navItem;
navItem.gotoAndStop(3);
}
拜托,现在已经好几个小时了,我错过了什么?
答案 0 :(得分:0)
我的猜测是:您应该将navItem变量更改为当前if块内的currentNav:
if (currentNav!=null) {
navItem.gotoAndStop(1);
}
看起来您想对当前活动项目(currentNav)进行一些更改。
UPD。:我的建议是:尝试将上面的代码更改为下一个代码
if (currentNav!=null) {
currentNav.gotoAndStop(1);
}
UPD 18-11-2015,切换按钮:
很难说我的代码是否有效(我没有整个项目来测试它),但看起来应该如此。
function navClick(e:MouseEvent):void
{
var navItem:MovieClip=e.target as MovieClip;
if (currentNav != null)
{
currentNav.gotoAndStop(1);
}
if(currentNav == navItem)
{
currentNav = null;
}else
{
currentNav = navItem;
navItem.gotoAndStop(3);
}
}