as3如何重复部分movieclip时间轴从标签到标签的次数

时间:2013-05-01 08:23:35

标签: actionscript-3 movieclip

我在时间轴上有一个约7个翻领的影片剪辑,我希望标签的每个部分重复2次,直到时间轴结束,并且影片剪辑时间轴上根本没有代码。我试图用if语句来做它并且它没有用,有没有办法用for循环来做它?

var repeat:Number = 2;
var repeating:Number = 1;
var mcFramelabel = 'label1';
var labelNum:Number = 1;
mc1.addEventListener(Event.ENTER_FRAME, repeatLabel);
function repeatLabel(e:Event):void
{
if (mc1.currentLabel == mcFrameLabel)
{
    repeatIt();
}
}

function repeatIt(){
var labelNumCont:Number;
if (repeating < repeat && mcFramelabel == 'label1'){
    repeating++;
    mc1.gotoAndPlay(2);
}else if (repeating < repeat && mcFramelabe != 'label1'){
    repeating++;
    labelNum++;
    labelNumCont = labelNum - 1;
    mcframelabel = 'label'+labelNumCont;
    mc1.gotoAndPlay(mcframelabel)
}else if (repeating == repeat){
    repeating = 1;
    labelNum++
    mcFramelabel = 'label'+labelnum;
    mc1.gotoAndplay(mcfameLable);
}
}

1 个答案:

答案 0 :(得分:0)

<强>更新

如果您正在将swfs加载到动画片段中,并且想要使用swf中的标签,请确保引用swf的时间轴标签而不是容器动画片段的标签。也就是说,如果你想控制movieclip之外的播放,基本实现仍然是相同的(除了需要不同的触发事件)。

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);
    }
}