更新
如果您将 swf 加载到您的影片剪辑中,并且想要使用 swf 中的标签,请确保您引用的是 swf 的时间线标签,而不是容器影片剪辑的标签。也就是说,如果您想在影片剪辑之外控制播放,则基本实现保持不变(除非需要不同的触发事件)。
mc1.addEventListener(Event.ENTER_FRAME, tick);
var count:Object = {};
function tick(e:Event):void {
if (mc1.currentFrameLabel != null) { // If the playhead is resting on a frame with a label...
for each (var label in mc1.currentLabels) { // loop through the mc's list of labels.
if (count.hasOwnProperty(label) == false) { // if we don't have a value for this label
count[label] = 1; // store it
break; // break the loop, and allow the playhead to continue.
} else if (count[label] < 2) { // If we haven't met our desired count
count[label]++; // increment
mc1.gotoAndPlay(label); // and go back to that label
break
}
}
}
}
我还没有测试过它,但我相信这应该可以解决问题。有趣的是,您可能想查看MovieClip.currentLabels。
请记住,所有相关代码都会在每次帧更新期间完全运行。循环将在它被调用的毫秒内执行它的所有代码,所以在这种情况下这不是你想要的。
您可以尝试为每个标签的播放存储一个计数,并在每个标签之前检查该计数。例如,假设您有以下时间线设置:
label1 check() label2
| | | |
0 1 2 3
你的代码看起来像这样......
var count:Object = {};
function check():void {
// Make sure this label exists in our count
if (count.hasOwnProperty(mc1.currentLabel) == false) {
count[mc1.currentLabel] = 1;
mc1.gotoAndPlay(mc1.currentLabel);
}
// If the label is already present in the count, then this will be our
// second playthru, and we can let the playhead continue to the next label.
}
或者,如果您想重播该帧 10 次,您可以通过这种方式增加它...
var count:Object = {};
var repeat:int = 10;
function check():void {
// Make sure this label exists in our count
if (count.hasOwnProperty(mc1.currentLabel) == false) {
count[mc1.currentLabel] = 1;
} else { // increment the count
count[mc1.currentLabel]++;
}
// If we haven't reached our goal, go back to the label.
if (count[mc1.currentLabel] != repeat) {
mc1.gotoAndPlay(mc1.currentLabel);
}
}