您应该可以通过给它们所有相同的实例名称来做到这一点(只要屏幕上一次只有一个)。
假设您有一个跨越所有 4 个帧的按钮,其实例名称为 navBtn,并且您为每个 MC1-4 剪辑指定了相同的实例名称 MC。您可以在第 1 帧上执行以下操作:
navBtn.addEventListener(MouseEvent.CLICK, navBtnClick);
function navBtnClick(e:Event):void {
if(MC.BC.currentFrame == 2){
MC.BC.gotoAndStop(1);
}else{
MC.BC.gotoAndStop(2);
}
}
再次阅读您的问题,也许正在寻找的是让每个剪辑在加载时自动转到其BC 孩子的同一帧?如果是这种情况,请按照@Organis 对您的问题的评论中的示例进行操作。这是您可以实现此目的的一种方法:
在主时间线的第一帧上创建两个变量:
var BC_NAV_CHANGE:String = "BC_NAV_CHANGE";
var BC_CurFrame:int = 1;
然后,当您需要更改 BC 对象的框架时,请执行以下操作:
//create a function that you call when you want to change the BC frame
function toggleBCFrame(e:Event = null){
MovieClip(root).BC_CurFrame = MovieClip(root).BC_CurFrame == 1 ? 2 : 1;
//the line above is a if/else shorthand, that is setting a new value to the `BC_CurFrame` var,
//if the current value is `1`, it will set it to `2`, otherwise it will set it to `1`
MovieClip(root).dispatchEvent(new Event(MovieClip(root).BC_NAV_CHANGE));
//this line (above) dispatches a event telling anything that's listening that the variable has changed
}
如果上面的代码在主时间线上,您可以放弃代码的所有MovieClip(root). 部分。
现在,在BC MovieClip(s) 的时间线上,输入以下代码:
//create a function that goes to and stops at the frame stored in the global variable
function updateFrame(e:Event = null){
gotoAndStop(MovieClip(root).BC_CurFrame);
}
//next listen for the BC_NAV_CHANGE event, and call the above update function above any time that event happens
MovieClip(root).addEventListener(MovieClip(root).BC_NAV_CHANGE, updateFrame);
//lastly, call the update function right away so when the BC clips loads it immediately goes to the correct frame
updateFrame();