开发者

determine is MovieClip playing now

开发者 https://www.devze.com 2023-02-27 02:09 出处:网络
I have movieClip (in a开发者_运维知识库s3) and I\'d like to know is this movieClip playing now

I have movieClip (in a开发者_运维知识库s3) and I'd like to know is this movieClip playing now

How can I do this?


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


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消