That's just getting a simple formated time from the date object. There are better ways of doing that.
Here is an updated version that is shorter and more efficient. <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import flash.utils.Timer; import flash.events.TimerEvent; private var timer:Timer; private function init():void { this.timer = new Timer(1000); this.timer.addEventListener(TimerEvent.TIMER, this.resetNow); this.timer.start(); } private function resetNow(event:TimerEvent):void { this.clock.text = new Date().toLocaleTimeString(); } ]]> </mx:Script> <mx:Panel x="55" y="43" width="487" height="371" layout="absolute" title="Time" creationComplete="this.init();"> <mx:Form width="100%" height="100%"> <mx:FormHeading label="Time"/> <mx:HRule width="100%"/> <mx:FormItem label="Now"> <mx:Text id="clock" text="" creationComplete="this.init();"/> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application> --- In [email protected], "Chad Gray" <[EMAIL PROTECTED]> wrote: > > Thanks Paul! > > I am so new to this stuff can you explain what this function is doing? > > private function set now(d:Date):void { > this.nowText = d.toTimeString(); > } > > > > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Paul DeCoursey > Sent: Thursday, March 22, 2007 12:24 PM > To: [email protected] > Subject: [flexcoders] Re: display current time > > I just did something like that.. > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute" initialize="this.init();"> > <mx:Script> > <![CDATA[ > import flash.utils.setInterval; > import flash.utils.clearInterval; > > private function init():void { > flash.utils.setInterval(this.resetNow, 1000); > } > > > private function resetNow():void { > this.now = new Date(); > } > > private function set now(d:Date):void { > this.nowText = d.toTimeString(); > } > > [Bindable] > private var nowText:String = ""; > > > ]]> > </mx:Script> > <mx:Panel x="55" y="43" width="487" height="371" layout="absolute" > title="Time" creationComplete="this.resetNow();"> > <mx:Form width="100%" height="100%"> > <mx:FormHeading label="Time"/> > <mx:HRule width="100%"/> > <mx:FormItem label="Now"> > <mx:Text text="{this.nowText}"/> > </mx:FormItem> > </mx:Form> > </mx:Panel> > </mx:Application> > > > You'll have to play around with DateFormatters to get the kind of > display you want. But as you can see it's very simple. Note however > that this could slow down the responsiveness of your app. > > Paul > > --- In [email protected], "Chad Gray" <cgray@> wrote: > > > > I need the current time in my flex app. > > > > Also is it possible to display the current time in the flex app > having it always current? So the user would watch the seconds and > minutes change? > > > > How is best handled? Is this an actionscript thing? > > > > Thanks, > > Chad > > > > > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links >

