Thanks James, sounds good enough to me and seems to work nicely. Many thanks
Paul -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Marsden Sent: 05 November 2006 10:44 To: Flashcoders mailing list Subject: Re: [Flashcoders] OOP advice for game It's a life saver in AS 2.0 It basically solves the problem of function scope in AS 2.0 (something that AS 3.0 comes with as standard - yay) In this case, it means that the global function setInterval knows where to locate and call the function (inside the class) - and also knows where to clear it when you want to clear it. I don't actually understand *why* this implementation for setInterval works - it doesn't really make sense... but then there's soo much about AS 2.0 that doesn't make sense... AS 3.0 is a tidy bedroom compared to AS 2.0's sloppy student digs... J Paul Steven wrote: > Ah brilliant - thanks James, much appreciated!! > > Will have to look up what this mx.utils.Delegate malarkey means though... > > Paul > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of James > Marsden > Sent: 05 November 2006 09:22 > To: Flashcoders mailing list > Subject: RE: [Flashcoders] OOP advice for game > > actually the private func there might need to be changed to public. > > I've had headaches getting intervals to clear properly, and this way works > for us :) > > Good luck! > > J > > > >> I'm assuming you're using AS 2.0 - inside WeatherManager.as: >> >> class WeatherManager >> { >> >> // private var to hold interval >> private var weatherTimer; >> >> // constructor >> public function WeatherManager() >> { >> weatherTimer = setInterval(mx.utils.Delegate.create(this, >> changeWeather), 5000); >> } >> >> // weather change func >> private function changeWeather() >> { >> // change the weather >> } >> >> // clear interval func >> public function cleanUp() >> { >> clearInterval(weatherTimer); >> } >> } >> >> >> // hope that helps! >> >> >> >> >>> I have done as you suggested and have created separate classes for the >>> balloon, ball, scoreboard and clouds and this all seems to work fine. >>> The >>> design pattern is based on an Observer pattern where these separate >>> objects >>> register themselves as observers of a WeatherManager object. >>> >>> I have created a WeatherManager.as class that broadcasts any updates to >>> the >>> weather to the observers. >>> >>> Now I need to have the WeatherManager periodically change the weather >>> conditions. I was thinking it should have some sort of internal timer >>> and >>> every say 5 seconds, it will amend the weather conditions. >>> >>> Not sure how best to create an internal timer - would I just use >>> setInterval >>> within the WeatherManager class? Or would it be better to create a timer >>> class and have a loop to continually check this timer? I have had real >>> problems in the past using setInterval in that they don't seem to clear. >>> >>> The game itself is time based and there is a time limit of 80 seconds so >>> there will need to be a timer for this too. Not sure if best to use just >>> one >>> timer for dealing with both or just let the WeatherManager have its own >>> timer and at the beginning of the game just start its timer and leave it >>> to >>> do its updates independently of the main game timer >>> >>> Any suggestions most appreciated >>> >>> Thanks >>> >>> Paul >>> >>> -----Original Message----- >>> From: [EMAIL PROTECTED] >>> [mailto:[EMAIL PROTECTED] On Behalf Of Weyert >>> de >>> Boer >>> Sent: 04 November 2006 17:52 >>> To: Flashcoders mailing list >>> Subject: Re: [Flashcoders] OOP advice for game >>> >>> Yeah, I made a little game myself and use the classes FoodPiece, Snake, >>> and GameWorld and SnakeGame. Meaning that SnakeGame handles all the >>> stuff such as start/stop game, score counting. The GameWorld is >>> responsible for all the drawing, and calling the update method of the >>> Snake instance, which will then have dedicated code to update itself. >>> >>> Works nicely! >>> >>> Weyert >>> _______________________________________________ >>> 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 >>> >>> >> _______________________________________________ >> 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 > > _______________________________________________ > 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 _______________________________________________ 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