A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Timer Event Not Firing! :(

  1. #1
    Game Developer
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    292

    Question Timer Event Not Firing! :(

    Hey all,

    I have a little flash app that I have running constantly on my server (I made it an exe). It runs great for a few days, but then eventually it just stops. I was able to track down exactly where it stops and I was hoping you could help me.

    Code:
    trace("test1");
    var myTimer:Timer = new Timer(5000, 1);
    myTimer.addEventListener(TimerEvent.TIMER, getData,false,0,true);
    myTimer.start();
    trace("test2");
    
    private function getData(event:TimerEvent):void {
         trace("test3");
    }
    The code above should call the function getData once after 5 seconds have passed. This works 99.99% of the time, but for some reason (usually after a few days of it running) it doesn't call the getData function.

    I have verified this through trace statements. When it eventually fails, it traces out test1, test2..... then nothing else. No test3.

    I'm assuming I need to add an event listener for the timer object to check if it fails for whatever reason. How do I do this?

    Or is there something else I am missing?

    Thanks for any advice you can give!
    Ryan
    Last edited by Sparticus007; 07-13-2010 at 03:58 PM. Reason: code tags misplaced

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    How often does it trace out test1 and test2? From what I see, those should happen at the very beginning, and not again.

    If you are creating multiple timers (one created between every test1 and test2), then you may have a significant memory leak.

  3. #3
    Game Developer
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    292
    Thanks for the reply

    I left out a few details, but here is the workflow of the app :

    1.) It starts the timer and I mentioned in my first post
    2.) after the 5 seconds have passed, I immediately call this in the getData function (myTimer is a global variable) :

    Code:
    myTimer.removeEventListener(TimerEvent.TIMER, getData);
    3.) I do a bunch of calculations in the getData function
    4.) after the calculations are done, I then call the function that restarts the 5 second timer (the code in my first post)

    So, it is an endless loop of checking for new data every 5 seconds.

    Hope that makes sense.

    Thanks for the help!

    Ryan
    Last edited by Sparticus007; 07-13-2010 at 05:25 PM.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    But you are creating a new Timer several times. Each Timer will have the listener added and then subsequently removed (ideally). Try to create the timer once, and use stop and reset/start rather than removing and re-adding the listener.

  5. #5
    Game Developer
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    292
    Hmm, well I do remove the eventlistener for each timer. But I see what your saying.

    I guess what I should be doing (if I undertsnad you correctly), it create a timer, set it to fire in 5 seconds, then after the timer event fires tell it to stop. Then after all the data has been processed just tell the timer to reset and start again.

    I'll look into this, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center