- package com.sina.utils
- {
- import flash.display.MovieClip;
-
- /**
- * .主要是解决一个单帧影片剪辑无法暂停和重播的问题
- * @author ant-zhangpeng@staff.sina.com.cn
- */
- public class MovieClipManage
- {
- private var _target:MovieClip;
- private var _type:String;
-
- /**
- * 构造函数
- * @param mc 目标影片剪辑
- */
- public function MovieClipManage(mc:MovieClip = null)
- {
- _target = mc;
- }
-
- private function goto(mc:MovieClip, frame:int = 0):void
- {
- if(!(mc is MovieClip))
- {
- throw new Error("MovieClipManage::: 目标不是movieClip");
- return;
- }
- frame > 0 ? mc[_type](frame) : mc[_type]();
-
- if (mc.numChildren > 0)
- {
- for (var i:int = 0; i < mc.numChildren; i++ )
- {
- if (mc.getChildAt(i) as MovieClip)
- {
- goto(mc.getChildAt(i) as MovieClip, frame);
- }
- }
- }
-
- }
-
- //--------------------API---------------------------------
- /**
- * 暂停影片剪辑
- */
- public function pause(target:MovieClip = null):void
- {
- _type = "stop";
- target = target || _target;
- goto(target);
- }
-
- /**
- * 恢复暂停影片剪辑
- */
- public function play(target:MovieClip = null):void
- {
- _type = "play";
- target = target || _target;
- goto(target);
- }
-
- /**
- * 停止影片剪辑到第一帧
- */
- public function stop(target:MovieClip = null):void
- {
- _type = "gotoAndStop";
- target = target || _target;
- goto(target, 1);
- }
-
- /**
- * 重播影片剪辑
- */
- public function replay(target:MovieClip = null):void
- {
- _type = "gotoAndPlay";
- target = target || _target;
- goto(target, 1);
- }
- }
-
- }
转载于:https://www.cnblogs.com/czjone/archive/2010/10/26/1861792.html