Safe remove

    public static function safeDestroy (obj:Dynamic, ?destroy:Bool=true) :Bool {
        
        if (obj == null) return false;
        
        var objs :Array<Dynamic> = Std.is (obj, Array) ? obj : [obj];
        
        for (o in objs) {
            if (o == null) continue;
            if (destroy)    try { o.destroy(); }
                            catch (e:Dynamic) { trace("[Error on object: "+o+", {"+e+"}"); }
            
            var parent = null; try { parent = o.parent; } catch (e:Dynamic) { trace(e); }
            if (parent != null) parent.removeChild ( o );
        }
        return true;
    }
    
    public static function safeRemove (obj:Dynamic) :Bool {
        return safeDestroy (obj, false);
    }

One function that will make the job of removing/destroying objects from stage shorter. You can pass an object or an array of objects without checking if they are instantiated. If you call safeDestroy a function named destroy will be safely called in each object.
Hope to be helpful, this is my most used static function.
version #6772, modified 2009-08-18 22:44:35 by cristibaluta