MovieClip.isPlaying
It’s actually sort of amazing that we haven’t had this property in older versions of Flash Player and AIR. MovieClip instances are unique in that they contain their own timeline, independent from the main timeline. Often, a developer will want to know whether or not a specific MovieClip instance is actually playing or not, and this has traditionally involved monitoring the current frame of the MovieClip to determine whether or not it is changing over time.
Making use of this new functionality is very direct, as MovieClip.isPlaying is simply a property of every MovieClip instance which, when invoked, returns a Boolean value of true for playing and false for stopped. In the following example, we create a MovieClip add it to the DisplayList, and then write the isPlaying property out onto a TextField.
package { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFormat; [SWF(width="600", height="500", backgroundColor="#CCCCCC")] public class CheckPlaying extends Sprite { private var face:MovieClip; private var traceField:TextField; public function CheckPlaying() { generateDisplayObjects(); } protected function generateDisplayObjects():void { face = new AngryFace() as MovieClip; face.x = stage.stageWidth/2; face.y = stage.stageHeight/2; face.stop(); face.addEventListener(MouseEvent.CLICK, toggleFacePlaying); addChild(face); var defaultFormat:TextFormat ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access