Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

isPlaying.as

Name: isPlaying() - sees if movieclip is playing
Author: senocular: www.senocular.com
Date: 1899-12-31T00:29:45.700
Documentation:
Movieclip ISPLAYING: determines if the playhead of
the current movieclip is moving or not.  If yes, true is
returned, if not, false.
 
Returns:
- returns true if the movieclip is playing, which is defined by the frame of the moveiclip
now being different from the frame of the movieclip in the previous frame. False is returned
if the movieclip is not playing or the frame of that clips timeline is the same as the
previous frame of the movie
 
Warning:
- This is meant to be continuously called within an enterFrame event.  The reason is because
isPlaying creates the _previousframe property it uses to check to see if the playhead has in
fact moved.  If this isnt used in this manner, isPlaying will base its determination of whether
or not the playhead is moving based on the last time it was called which was the last time it
created the _previousframe property for that given object.

Example:
// moveiclip which only moves down while the main timeline is playing
onClipEvent(enterFrame){
	if (_root.isPlaying()) _y++;
}

1
2
3
4
5
6
7
MovieClip.prototype.isPlaying = function(){
	if (this._previousframe == undefined) this._previousframe = this._currentframe;
	if (this._previousframe == this._currentframe) var playing = false;
	else var playing = true;
	this._previousframe = this._currentframe;
	return playing;
}