To stop the 'ping' just throw a 'timer.stop()' into your stopPing()
function.  It worked for me.  I also removed the timer.reset();
timer.start(); from the sayPing() function.  I'm not sure that you need
those.

This should help cure the 'tinnitus'  :-)

Also - did you notice that you did not place the 'click' handler in the
button?  It's in the TextArea component.

Others can weigh in on deleting an instance of a class ... I think that the
VM has a memory manager that takes care of that for you?






                                                                                                                              
                                                                                                                              
             "Sonja Duijvesteijn"              To: flexcoders@yahoogroups.com                                                 
             <[EMAIL PROTECTED]>           cc:                                                                            
             Sent by:                          Subject:  [flexcoders] delete class instances                                  
             flexcoders@yahoogroups.com                                                                                       
             05/16/2006 02:54 PM                                                                                              
             Please respond to                                                                                                
             flexcoders                                                                                                       
                                                                                                                              
                                                                                                                              




I've been working with Flex since last Februari, and since then I've been
having a problem with classes. Since it's seemed foolish that I could not
find the solution myself I've been hesitant to ask but here goes.

How do you delete and instance of a class?! I've set up a small example
with a class 'PingTime' which says 'ping' every second. And I'd like it to
stop, but not just stop but completely remove the class out of memory. How
do I do that? I'm sure there's a solution, and probably it's in the docs
somewhere, but I just can't find it.

How do I make the pinging stop?

Kind regards,
Sonja Duijvesteijn

package sd.classes {
  import flash.utils.Timer;
  import flash.events.TimerEvent;
  import mx.core.Application;

    public class PingTime    {
        private var timer:Timer;

        public function PingTime() {
        timer = new Timer(1000);
        timer.addEventListener(TimerEvent.TIMER, sayPing);
        timer.start();
        }

        private function sayPing(event:TimerEvent):void {
            Application.application.pingTxt.text += "ping "
            timer.reset();
            timer.start();
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import sd.classes.PingTime;
            private var ping:PingTime;

            private function init():void {
                ping = new PingTime();
            }

            private function removePing():void {

            }
        ]]>
    </mx:Script>
    <mx:Button x="10" y="10" label="stop Ping"/>
    <mx:TextArea x="10" y="56" width="445" height="143"
click="removePing()" id="pingTxt"/>
</mx:Application>




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com



                                                            SPONSORED LINKS
                                                                  
Web site design     Computer software       Software design and  
development         development             development          
                                                                  
Macromedia flex     Software development                         
                     best practice                                
                                                                  


                            YAHOO! GROUPS LINKS

       Visit your group "flexcoders" on the web.

       To unsubscribe from this group, send an email to:
       [EMAIL PROTECTED]

       Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.





---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use
of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt from
disclosure.  If you are not the intended recipient, you are notified that
any dissemination, distribution or copying of this communication is
strictly prohibited.  If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
---------------------------------------------------------------------------



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to