determine is MovieClip playing now

一笑奈何 提交于 2020-01-03 18:05:32

问题


I have movieClip (in as3) and I'd like to know is this movieClip playing now

How can I do this?


回答1:


As crazy as it is, there is no built in way to do this (although it should be). Two options have a flag that you swap when play/stop is called.

var mc_playing:Boolean = false;

mc_playing = true;
mc.play();



mc_playing = false;
mc.stop();

Or you could extend the MovieClip class to create your own playing property.

class SuperMovieClip extends MovieClip {
    private var _playing:Boolean = false;

    public function SuperMovieClip() {

    }

    override public function play():void {
        _playing = true;
        super.play();
    }

    override public function stop():void {
        _playing = false;
        super.stop();
    }

    public get function playing():Boolean {
        return _playing;
    }

}

Then just make your mc link to SuperMovieClip instead of MovieClip




回答2:


If you don´t want to override the Core classes you could create a Controller class to handle these kind of checks on a time update. The Controller holds the clips to check and stores currentFrame on an update. Using this method you can use one controller to control many clips and you only ask the controller if a clip is playing. It is easy to add functionality to a controller later on without having to change the class to check.

_controller = new TimelineClipController(); 
_controller.add(_animationClip1);
_controller.add(_animationClip2);

// on update (ENTER_FRAME, CUSTOM EVENT or TIMER)
_controller.update();

// check if playing
trace(_controller.isClipPlaying(_animationClip1));

Another way of doing it is to add scripts runtime. Personally I don´t like this one but in some cases it can be nice. Say you add a

//add script to star timeline on frame 2
_animationClip1.addFrameScript(1, frameFunction); // (zero based)


来源:https://stackoverflow.com/questions/5693414/determine-is-movieclip-playing-now

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!