You can use a singleton. It's just important that the intervals be managed in a single location. _root can be used by as1 or as2 programmers. AS3 supports a document class and support for inner classes which means (through some creative engineering) singletons as well, no need for root.
1) setInterval is not accurate. Try moving the window around and see if the function gets called when it's supposed to. Keep a timer and compare the interval call to the time over say a minute to 2 minute period. You could be off by several or more seconds, and if you move the window around like crazy your 1 second interval could be called 7 seconds later. 2) Create your own class which does this. 3) onEnterFrame to check intervals (in a singleton) or single instance class, or root! 4) Even with a reference to the interval the interval may not always be deleted. Sorry, it's not. Do some tests. This is especially the case if you use delegates with your setinterval. The management problem for performance gets even worse. Making sure you delete and clear everything. But in my experience the intervals don't clear like they should even went set to self-destruct. 5) The 3 parameter setinterval call is not for scope, its for the object containing the method you want to call, if thats what you meant by scope. The object could be removed and the interval continue to be called. 6) Why go through all this headache when you can easily write your own interval class which is accurate and deletes itself when told? *regards* Kalani PS -(Try and be helpful rather than sticking your nose up at people) -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Muzak Sent: Wednesday, February 28, 2007 7:04 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. As a posted last week or something, there's a few things to keep in mind when using setInterval - clear interval before setting it - always use this syntax setInterval(scope, "method", interval) - and never use this syntax setInterval(function, interval) - keep a reference to the interval - remove it when done If things go haywire, you're doing something wrong and you probably forgot one of the above. If you're referring to everything using _root, code in the main timeline and advise others to do so, please join the flashnewbie list http://chattyfig.figleaf.com/mailman/listinfo/flashnewbie regards, Muzak ----- Original Message ----- From: "Kalani Bright" <[EMAIL PROTECTED]> To: <flashcoders@chattyfig.figleaf.com> Sent: Thursday, March 01, 2007 3:15 AM Subject: RE: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. > When I was using AS2 I found that no matter what there were always memory > leaks with set interval and even after I explicitly tell Flash to remove the > interval it never got removed... > > So even though I never wrote it I would offer the following advice, which is > to *almost* not use setInterval at all. Just use it once, for the root... > 1) Move all functionality for intervals to a script on the root > 2) The root is always available, and you won't have intervals all over the > place > 3) Create only one interval for a function on the root which is responsible > for calling functions > 4) The function should get the same sort of information as whats required by > setInterval. > 5) Call functions based on the timer. Time since movie started. A little > math should test if the objects which are registered with your script should > be called again. I would also recommend enabling this function to support > something like "call this function X times every 1000 ms). Rather than > call this object every 1000ms. That way you can delete it automatically if > its reached that number. > 6) That script keeps information on what intervals are set > 7) The script periodically checks for objects which no longer exists and > deletes them from the interval array. > 8) Intervals are set or removed by calling a root function. Use the > delegate class to say which function gets the interval callback and also > pass a reference to the object. > > Good luck, > > Kalani > > _______________________________________________ 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 _______________________________________________ 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