简体   繁体   中英

ENTER_FRAME event idle occurrence or was gotoAndPlay called?

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

As far as I understand, you need to know next two things: 1). When movieclip advances to next frame with the new frame label; 2). When the next frame has the same label as the previous.

First of all MovieClip doesn't has "isPlaying" property. It sounds unrealistic, but there is no built-in method to check whether MC is playing. So e.target.isPlaying will always return false; therefore your second "if" statement will also always return false.

Also you don't need that "isPlaying" check at all because MovieClip dispatches Event.ENTER_FRAME only when it plays.

So this will work:

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

But maybe I didn't understand your question?

I ended up solving this problem by manually storing frame label indices in the class constructor. The MovieClip property currentFrameLabel should take care of this, however my tests show that it is always undefined.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM