Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cj.utils {
- import flash.display.Sprite;
- import flash.display.MovieClip;
- import flash.display.Loader;
- import flash.display.Bitmap;
- import flash.display.Shape;
- import flash.media.Video;
- import flash.display.DisplayObjectContainer;
- // optional
- import com.greensock.TweenLite;
- // this class acts as a recursive cleaner and can be helpful when advanced cleanup is necessary
- public final class Cleaner {
- // passes every child through the clean function
- private static function removeIt(obj:Object):void {
- if(obj is DisplayObjectContainer) {
- var it:Object;
- while(obj.numChildren) {
- it = obj.getChildAt(0);
- obj.removeChild(it);
- clean(it);
- }
- }
- }
- // finds what the object is and performs specific cleanup
- public static function clean(obj:Object):void {
- TweenLite.killTweensOf(obj);
- if(obj is MovieClip) {
- obj.stop();
- removeIt(obj);
- }
- else if(obj is Sprite) {
- removeIt(obj);
- }
- else if(obj is Bitmap) {
- obj.bitmapData.dispose();
- }
- else if(obj is Loader) {
- if(obj.content) {
- removeIt(obj.content);
- obj.unloadAndStop();
- }
- try {
- obj.close();
- }
- catch(event:*) {};
- }
- else if(obj is Shape) {
- obj.graphics.clear();
- }
- else if(obj is Video) {
- obj.clear();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment