可以控制多层嵌套的movieClip播放和暂停

  1. package com.sina.utils
  2. {
  3.         import flash.display.MovieClip;
  4.        
  5.         /**
  6.          * .主要是解决一个单帧影片剪辑无法暂停和重播的问题
  7.          * @author ant-zhangpeng@staff.sina.com.cn
  8.          */
  9.         public class MovieClipManage
  10.         {
  11.                 private var _target:MovieClip;
  12.                 private var _type:String;
  13.                
  14.                 /**
  15.                  * 构造函数
  16.                  * @param        mc  目标影片剪辑
  17.                  */
  18.                 public function MovieClipManage(mc:MovieClip = null)
  19.                 {
  20.                         _target = mc;
  21.                 }
  22.                
  23.                 private function goto(mc:MovieClip, frame:int = 0):void
  24.                 {
  25.                         if(!(mc is MovieClip))
  26.                         {
  27.                                 throw new Error("MovieClipManage::: 目标不是movieClip");
  28.                                 return;
  29.                         }
  30.                         frame > 0 ?  mc[_type](frame) :  mc[_type]();
  31.                        
  32.                         if (mc.numChildren > 0)
  33.                         {
  34.                                 for (var i:int = 0; i < mc.numChildren; i++ )
  35.                             {
  36.                                         if (mc.getChildAt(i) as MovieClip)
  37.                                         {
  38.                                                 goto(mc.getChildAt(i) as MovieClip, frame);
  39.                                         }
  40.                                 }
  41.                         }
  42.                        
  43.                 }
  44.                
  45.                 //--------------------API---------------------------------
  46.                 /**
  47.                  * 暂停影片剪辑
  48.                  */
  49.                 public function pause(target:MovieClip = null):void
  50.                 {
  51.                         _type = "stop";
  52.                         target = target || _target;
  53.                         goto(target);
  54.                 }
  55.                
  56.                 /**
  57.                  * 恢复暂停影片剪辑
  58.                  */
  59.                 public function play(target:MovieClip = null):void
  60.                 {
  61.                         _type = "play";
  62.                         target = target || _target;
  63.                         goto(target);
  64.                 }
  65.                
  66.                 /**
  67.                  * 停止影片剪辑到第一帧
  68.                  */
  69.                 public function stop(target:MovieClip = null):void
  70.                 {
  71.                         _type = "gotoAndStop";
  72.                         target = target || _target;
  73.                         goto(target, 1);
  74.                 }
  75.                
  76.                 /**
  77.                  * 重播影片剪辑
  78.                  */
  79.                 public function replay(target:MovieClip = null):void
  80.                 {
  81.                         _type = "gotoAndPlay";
  82.                         target = target || _target;
  83.                         goto(target, 1);
  84.                 }
  85.         }
  86.        
  87. }
posted @ 2010-10-26 19:31  czjone  阅读(546)  评论(0编辑  收藏  举报