【转】一个工具类(可以控制多层嵌套的movieClip)

好多人也应该遇到和我一样的问题,当设计师给了我们一个多层嵌套的movieClip时,我们在写代码时无法将movieClip完全停止掉,主要是基于好多movieClip有深层嵌套,主时间轴不在最上层导致的,所以基于这个原因写了下面的类。



看代码:(有很详细的注释)
  1. package com.sina.utils
  2. {
  3. import flash.display.MovieClip;
  4. public class MovieClipManage
  5. {
  6. private var_target:MovieClip;
  7. private var_type:String;
  8. public functionMovieClipManage(mc:MovieClip = null)
  9. {
  10. _target =mc;
  11. }
  12. private functiongoto(mc:MovieClip, frame:int = 0):void
  13. {
  14. if(!(mc isMovieClip))
  15. {
  16. throw new Error("MovieClipManage:::目标不是movieClip");
  17. return;
  18. }
  19. frame >0 ?  mc[_type](frame):  mc[_type]();
  20. if(mc.numChildren > 0)
  21. {
  22. for (var i:int = 0; i < mc.numChildren; i++)
  23. {
  24. if (mc.getChildAt(i) asMovieClip)
  25. {
  26. goto(mc.getChildAt(i) as MovieClip, frame);
  27. }
  28. }
  29. }
  30. }
  31. //--------------------API---------------------------------
  32. public functionpause(target:MovieClip = null):void
  33. {
  34. _type ="stop";
  35. target =target || _target;
  36. goto(target);
  37. }
  38. public functionplay(target:MovieClip = null):void
  39. {
  40. _type ="play";
  41. target =target || _target;
  42. goto(target);
  43. }
  44. public functionstop(target:MovieClip = null):void
  45. {
  46. _type ="gotoAndStop";
  47. target =target || _target;
  48. goto(target, 1);
  49. }
  50. public functionreplay(target:MovieClip = null):void
  51. {
  52. _type ="gotoAndPlay";
  53. target =target || _target;
  54. goto(target, 1);
  55. }
  56. }
  57. }

复制代码

//---------------------------------------------------------------------



实现原理:主要用到了递归的原理来循环找到底层的movieClip原件,然后执行相应的操作来达到将所有嵌套的原件暂停,重播等功能。

原文地址:http://www.99ria.com/blog/?p=230

上一篇:jquery 点点滴滴小记


下一篇:MySql资料总全