0

I have an MC with frame labels that are jumped through. Currently, I can detect when it starts a new label, but I also want to be able to restart the actions should the current label get called with gotoAndPlay() without ENTER_FRAME calling it 30 times per second. Any idea how to filter that out?

    private function onNewFrame(e:Event) {

        if(e.target.currentLabel != _currentLabel) {
            // started new label (working)
            trace("New label: "+ e.target.currentLabel);

        }else if(e.target.currentFrame == _currentFrame && e.target.isPlaying) {
            // repeated frame (doesn't work)
            trace("Repeated label: "+ e.target.currentFrame);
        }

        _currentFrame = e.target.currentFrame;
        _currentLabel = e.target.currentLabel;
    }
4

2 回答 2

0

据我了解,您需要知道接下来的两件事:1)。当movieclip使用新的帧标签前进到下一帧时;2)。当下一帧与前一帧具有相同的标签时。

首先,MovieClip 没有“isPlaying”属性。听起来不太现实,但没有内置方法来检查 MC 是否正在播放。所以 e.target.isPlaying 总是会返回 false;因此,您的第二个“if”语句也将始终返回 false。

此外,您根本不需要“isPlaying”检查,因为 MovieClip 仅在播放时调度 Event.ENTER_FRAME。

所以这将起作用:

var testMc:TestMC = new TestMC();
testMc.addEventListener(Event.ENTER_FRAME, onNewFrame);
testMc.play();

private function onNewFrame(e:Event):void
{

    if (e.target.currentLabel != _currentLabel)
    {
        // started new label (working)
        trace("New label: " + e.target.currentLabel);

    }
    else if (e.target.currentFrame !== _currentFrame)
    {
        // started frame with the same label
        trace("New frame with same label: " + e.target.currentFrame);
    }

    _currentFrame = e.target.currentFrame;
    _currentLabel = e.target.currentLabel;
}

但也许我不明白你的问题?

于 2013-08-24T11:40:43.053 回答
0

我最终通过在类构造函数中手动存储帧标签索引来解决这个问题。MovieClip 属性 currentFrameLabel 应该解决这个问题,但是我的测试表明它始终是未定义的。

public class DynamicMC extends MovieClip {

    private var _currentLabel:String;
    private var _currentFrame:int;

    private var _labels:Object = {};

    public function DynamicPlanComparison() {
        super();

        findLabels();
    }

    private function findLabels():void {
        for(var i:uint = 0; i < currentLabels.length; i++) {
            var l:FrameLabel = currentLabels[i];
            _labels[l.name] = l;

        }
    }

    private function onNewFrame(e:Event) {
        if(e.target.currentLabel != _currentLabel) {
            // started new label
            trace("New label: "+ e.target.currentLabel);

        }else if(_labels[e.target.currentLabel].frame == e.target.currentFrame) {
            // repeated label
            trace("Repeated label: "+ e.target.currentLabel);
        }

        _currentFrame = e.target.currentFrame;
        _currentLabel = e.target.currentLabel;
    }
}
于 2013-08-26T15:24:51.617 回答