好多人也应该遇到和我一样的问题,当设计师给了我们一个多层嵌套的movieClip时,我们在写代码时无法将movieClip完全停止掉,主要是基于好多movieClip有深层嵌套,主时间轴不在最上层导致的,所以基于这个原因写了下面的类。
看代码:(有很详细的注释)
看代码:(有很详细的注释)
- package com.sina.utils
- {
- import flash.display.MovieClip;
- public class MovieClipManage
- {
- private var_target:MovieClip;
- private var_type:String;
- public functionMovieClipManage(mc:MovieClip = null)
- {
- _target =mc;
- }
- private functiongoto(mc:MovieClip, frame:int = 0):void
- {
- if(!(mc isMovieClip))
- {
- 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) asMovieClip)
- {
- goto(mc.getChildAt(i) as MovieClip, frame);
- }
- }
- }
- }
- //--------------------API---------------------------------
- public functionpause(target:MovieClip = null):void
- {
- _type ="stop";
- target =target || _target;
- goto(target);
- }
- public functionplay(target:MovieClip = null):void
- {
- _type ="play";
- target =target || _target;
- goto(target);
- }
- public functionstop(target:MovieClip = null):void
- {
- _type ="gotoAndStop";
- target =target || _target;
- goto(target, 1);
- }
- public functionreplay(target:MovieClip = null):void
- {
- _type ="gotoAndPlay";
- target =target || _target;
- goto(target, 1);
- }
- }
- }
复制代码
//---------------------------------------------------------------------
实现原理:主要用到了递归的原理来循环找到底层的movieClip原件,然后执行相应的操作来达到将所有嵌套的原件暂停,重播等功能。
原文地址:http://www.99ria.com/blog/?p=230