Flash: Final solution -KillerBeacon

May 13th, 2005 by Luis

Finally I have find a clean solution in order to remove from the stage TextFields that were not created with createTextField() or movie clip instances that were not created with duplicateMovieClip(), MovieClip.duplicateMovieClip(), or MovieClip.attachMovie().

KILLER BEACON:

Actionscript:
  1. /**
  2. * KillerBeacon, version 1
  3. * @class:   KillerBeacon
  4. * @author:  luis@lessrain.com
  5. * @version: 1.0
  6. */
  7.  
  8. import lessrain.lib.utils.DepthManager;
  9.  
  10. class KillerBeacon
  11. {
  12.     private static var _oInstance:KillerBeacon = null;
  13.    
  14.     function KillerBeacon (){}
  15.  
  16.     public static function getInstance ():KillerBeacon
  17.     {
  18.         if (_oInstance == null) {
  19.             KillerBeacon._oInstance = new KillerBeacon ();
  20.         }
  21.         return KillerBeacon._oInstance;
  22.     }
  23.    
  24.     public function destroy (o:Object):Void
  25.     {
  26.         var dm:DepthManager = DepthManager.getInstance ();
  27.         var target:MovieClip = o._parent;
  28.         var nextDepth:Number=dm.getNextDepth (target)
  29.         var tempKiller:MovieClip = target.createEmptyMovieClip ('killer', nextDepth);
  30.        
  31.         tempKiller.swapDepths (o);
  32.         (typeof (o) == 'movieclip') ? o.removeMovieClip () : o.removeTextField ();
  33.        
  34.         // remove killer mc
  35.         tempKiller.swapDepths (nextDepth);
  36.         tempKiller.removeMovieClip ();
  37.     }
  38. }


USAGE:

Actionscript:
  1. var killer=KillerBeacon.getInstance ().destroy(myTextField);


NOTE:

If you export the movie as flash 7 there is not need of the DepthManager utility , you can simply use the built in movieclip method getNextHighestDepth()

Actionscript:
  1. var tempKiller:MovieClip = target.createEmptyMovieClip ('killer',target.getNextHighestDepth());


3 Responses to “Flash: Final solution -KillerBeacon”

  1. lessrain blog » Blog Archive » Flash: Depth Control Says:

    […] ith duplicateMovieClip(), MovieClip.duplicateMovieClip(), or MovieClip.attachMovie() using swapDepths(). Small DepthManager Utility to use when you export as Flash 6: ActionScript: /** ************ […]

  2. Diego Guebel Says:

    Hi there, I was taking a look at your code when I realize that it is impossible to use the build-in depthmanager class, because it doesnt have a “getNextDepth()” method.
    I guess it might be a method of you class.
    Is there any link to get your depthmanager approuch?
    thanks in advance. Diego.

  3. Luis Says:

    The build in method uses getNextHighestDepth() instead of getNextDepth(), and you can see the depthManager class here:

    http://www.blog.lessrain.com/?p=33

Leave a Reply