Guest User

Untitled

a guest
Jan 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package cj.utils {
  2.  
  3. import flash.display.Sprite;
  4. import flash.display.MovieClip;
  5. import flash.display.Loader;
  6. import flash.display.Bitmap;
  7. import flash.display.Shape;
  8. import flash.media.Video;
  9. import flash.display.DisplayObjectContainer;
  10.  
  11. // optional
  12. import com.greensock.TweenLite;
  13.  
  14. // this class acts as a recursive cleaner and can be helpful when advanced cleanup is necessary
  15. public final class Cleaner {
  16.  
  17. // passes every child through the clean function
  18. private static function removeIt(obj:Object):void {
  19.  
  20. if(obj is DisplayObjectContainer) {
  21.  
  22. var it:Object;
  23.  
  24. while(obj.numChildren) {
  25.  
  26. it = obj.getChildAt(0);
  27. obj.removeChild(it);
  28.  
  29. clean(it);
  30.  
  31. }
  32. }
  33. }
  34.  
  35. // finds what the object is and performs specific cleanup
  36. public static function clean(obj:Object):void {
  37.  
  38. TweenLite.killTweensOf(obj);
  39.  
  40. if(obj is MovieClip) {
  41.  
  42. obj.stop();
  43. removeIt(obj);
  44.  
  45. }
  46. else if(obj is Sprite) {
  47.  
  48. removeIt(obj);
  49.  
  50. }
  51. else if(obj is Bitmap) {
  52.  
  53. obj.bitmapData.dispose();
  54.  
  55. }
  56. else if(obj is Loader) {
  57.  
  58. if(obj.content) {
  59.  
  60. removeIt(obj.content);
  61. obj.unloadAndStop();
  62.  
  63. }
  64.  
  65. try {
  66. obj.close();
  67. }
  68. catch(event:*) {};
  69.  
  70. }
  71. else if(obj is Shape) {
  72.  
  73. obj.graphics.clear();
  74.  
  75. }
  76. else if(obj is Video) {
  77.  
  78. obj.clear();
  79.  
  80. }
  81.  
  82. }
  83.  
  84. }
  85.  
  86. }
Add Comment
Please, Sign In to add comment