Hi,

Best practices say that when done with an event listener, it should be
removed.  If you're not removing it (them) anywhere else, you should
remove it with your "destroy" function.  This is also an excellent time
to kill any streams, stop sounds, stop timers, etc.  In fact, it's
recommended that your AS3 scripts do clean up things like this.  In AS3,
removing items from the display list doesn't destroy the objects like it
did in AS2. 

I try to include the following in any movie clip that is loaded:
---
function unloadHandler(event:Event):void {
        /*
        in here clean things up such as
        * null out any references to loaded content
                var myVar = myLoader.contentLoaderInfo.someVar
                => myVar = null;
        * unload any swf's that were loaded so they can also clean up on
unload
        * stop any sounds from playing
                this might mean SoundMixer.stopAll();
                or it might mean stopping a moiveclip (like with a .mov
on it)
        * close any LocalConnections, NetConnections, NetStreams
        * return any global properties to their default
        * null out any Camera or Microphones
        * removeEventListener for any that weren't by their natural flow
        * clearIntervals
        * stop any Timers
        */
        root.loaderInfo.removeEventListener("unload", unloadHandler);
}

root.loaderInfo.addEventListener("unload", unloadHandler);
---

This could be adapted for classes that are instantiated.

-Erica
Flash Player QE
 
> Message: 1
> Date: Sat, 24 Feb 2007 08:45:43 -0800 (PST)
> From: badi malik <[EMAIL PROTECTED]>
> Subject: Re: [Flashcoders] [AS3] Timers behaving erratically
> To: flashcoders@chattyfig.figleaf.com
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=iso-8859-1
> 
> i've had this happen many times and even posted to the list 
> about it....i use the debugger that comes with the flash ide 
> alot and only then can i see what's happening...if you look 
> at the instances using the debugger you can see that the 
> instances haven't cleared their values. what i've done in the 
> past is make sure that i call removeMovieClip as well as call 
> delete, and ....pray! :)
> 
> hope this helps
> 
> ----- Original Message ----
> From: Daniel Thompson <[EMAIL PROTECTED]>
> To: flashcoders@chattyfig.figleaf.com
> Sent: Friday, February 23, 2007 6:13:07 PM
> Subject: RE: [Flashcoders] [AS3] Timers behaving erratically
> 
> > classes. The second time this class is instantiated, the 
> timers don't 
> > fire. Any reason why this is happening?
> 
> Actually, nowhere in the application they aren't firing.
> Here's the code that disables the application:
> 
> 
> 
>     public static function disable(message:String):void {
>       with (_instance) {
>         var snapshot:Bitmap = takeSnapshot();
> 
>         destroyForm();
> 
>         _container.addChildAt(snapshot, 0);
>         _container.addChildAt(drawCurtains(), 1);
>         _container.stage.addEventListener(MouseEvent.CLICK,
> mouseClickHandler);
>         
>         showAlert(message);
> 
>         _container.stage.invalidate();
>         
>         _enabled = false;
>       }
>     }
> 
> 
>     private function destroyForm():void {
>       _container.removeChild(_container.getChildByName("form"));
>       _form = null;
>     }
> 
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to