[flexcoders] Re: Timer to run function every 30 min

2006-08-06 Thread richmcgillicuddy
From the docs:


package {
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;

public class TimerExample extends Sprite {

public function TimerExample() {
var myTimer:Timer = new Timer(1000, 2);
myTimer.addEventListener(timer, timerHandler);
myTimer.start();
}

public function timerHandler(event:TimerEvent):void {
trace(timerHandler:  + event);
}
}
}


so your 'code' would look something like:
   // Using the suggestion from an earlier post, use the interval
as the default
 // Also, make it public var so you can adjust it if you want,
have a slider to offer more frequent updates or less frequent updates
or turn off.  This would be myTimer.delay = slider.value or something
similar...
  var interval:Number = 60 * 30 * 1000;
  // Leave off second param here to make it go indefinitely
  var myTimer:Timer = new Timer(interval);


  public function initTimer: void {
  myTimer.addEventlistener(timer, timerHandler);
  myTimer.start();
}
  public function timerHandler(event:TimerEvent):void {
trace(timerHandler:  + event);
 // Lookup weather, update datasets, update display
 // Don't know yet if you need to turn off timer, then turn on
at end in case update takes too long.
}
--- In flexcoders@yahoogroups.com, David Brown [EMAIL PROTECTED] wrote:

 Thank you for you're help.  The timer event is the part I am having
trouble with.  I don't know how to write or where to start.  Any
suggestions would be great.
 
 David
 
   - Original Message - 
   From: sinatosk 
   To: flexcoders@yahoogroups.com 
   Sent: Saturday, August 05, 2006 5:41 PM
   Subject: Re: [flexcoders] Timer to run function every 30 min
 
 
   60 * 30 * 1000
 
   60 seconds
   times
   30 minutes
   times
   1000 miliseconds
   equals
   180
 
   I recommend using 60 * 30 * 1000 instead of the 180 so
it's easier for you to change/debug 
 
   and then just add an event listener on timer event name along
with the function you want it to call upon 30 minutes and then your
done :p
 
 
 
   On 05/08/06, David Brown [EMAIL PROTECTED] wrote:
 
 Hello all,
 
 I could use some help.  I have been
livedocs.macromedia.com/flex/2docs looking for a way to create a timer
function that would execute a function every 30 min.  I found an
example of mytimer and looked at a example for simple analog clock. 
But I am having a hard time understanding how it relates to my code. 
Below is a code snipet.
 
 I would like to run the InitApp() function every 30 min.  That
should refresh my two datagrids that inturn will update my screen.
 
 Any help would be great.
 
 Thank 
 David
 
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
layout=absolute width=500 height=56
backgroundGradientColors=[#ff, #ff]
creationComplete=initVars() horizontalAlign=center
verticalAlign=middle borderColor=#ff backgroundColor=#ff
borderStyle=solid borderThickness=1
  mx:Script
 ![CDATA[
import mx.logging.LogEvent;
/* import flash.events.MouseEvent;
import mx.events.FlexEvent; */
import mx.styles.CSSStyleDeclaration;
  import mx.effects.*;
import mx.events.*;
  import mx.rpc.events.*;
  import mx.controls.Alert;
import mx.managers.PopUpManager;
import flash.events.Event;
   import flash.events.TimerEvent;
   import flash.utils.Timer;   
 import mx.controls.Alert;
 import mx.collections.*;
 import flash.net.*;
 import flash.display.Sprite;
   [Bindable] 
  public var mylocID:String;
 
   // Assign values to new properties.
  private function initVars():void {
 InitApp();
  }
 public function InitApp():void
{ 
 // assign values passed from the html object flashvars
 mylocID = Application.application.parameters.mylocID;
 // if no value passed from the html object tag then assign value
 if (mylocID == null) {
  mylocID = 29223;
 }
 // get weather
 weatherSvc.qryCurrentWeather(mylocID);
 weatherSvc.qryExtendedWeather(mylocID);
 // set focus on the first row of the grids
 dgCurrentWeather.selectedIndex = 0;
 dgExtendedWeather.selectedIndex = 0; 
}

  ]]
 /mx:Script
 
  mx:RemoteObject id=weatherSvc destination=ColdFusion
source=Widgets.cfc.widgets showBusyCursor=true /








--
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

* To visit your group on the web, go

[flexcoders] Re: Timer to run function every 30 min

2006-08-06 Thread David Brown
Thank you for your help.  I managed to get a timer function written, 
but everytime the timerEvent runs it blanks out the display.

The page loads and displays the weather and then calls the 
timerExample every second (for testing).  But each time the 
TimerEvent runs the weather data displays, but disapears just as 
soon as it displays. While the timer is counting to the next event 
the weather does not display.  Then after it's complete it leaves 
the display blank.

Below is the entire code.  I would be greatful for any suggestions.  
Maybe its the datagrid, just not sure.

David

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; 
layout=absolute width=490 height=56 
backgroundGradientColors=[#ff, #ff] 
creationComplete=initVars() horizontalAlign=center 
verticalAlign=middle borderColor=#ff 
backgroundColor=#ff borderStyle=solid borderThickness=1
mx:Script
![CDATA[
import mx.logging.LogEvent;
/* import flash.events.MouseEvent;
import mx.events.FlexEvent; */
import mx.styles.CSSStyleDeclaration;
import mx.utils.ArrayUtil;
import mx.effects.*;
import mx.events.*;
import mx.rpc.events.*;
import mx.managers.PopUpManager;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.net.*;

[Bindable]  
public var mylocID:String;

// Assign values to new properties.
private function initVars():void {
InitApp();
//  ShortTimer();
}
public function InitApp():void
{   
// assign values passed from the 
html object flashvars
mylocID = 
Application.application.parameters.mylocID;
// if no value passed from the html 
object tag then assign value
if (mylocID == null) {
mylocID = 29223;
}
// get weather
weatherSvc.qryCurrentWeather
(lbmylocid.text);
weatherSvc.qryExtendedWeather
(lbmylocid.text);

// set focus on the first row of the 
grids
dgCurrentWeather.selectedIndex = 0;
dgExtendedWeather.selectedIndex = 0;
TimerExample();
}

public function TimerExample() {
var myTimer:Timer = new Timer(1000, 5);
myTimer.addEventListener(timer, timerHandler);
myTimer.start();
}

public function timerHandler(event:TimerEvent):void {
// get weather
weatherSvc.qryCurrentWeather(lbmylocid.text);
weatherSvc.qryExtendedWeather
(lbmylocid.text);   
}


 ]]
/mx:Script

mx:RemoteObject id=weatherSvc destination=ColdFusion 
source=Widgets.cfc.widgets showBusyCursor=true /

!-- Declare a formatter and specify formatting properties. --
mx:DateFormatter id=StandardDateFormat 
formatString=MM/DD/ @ L:NN A/
!-- holds the current weather --
mx:DataGrid visible=false height=50 width=50 
id=dgCurrentWeather 
dataProvider={weatherSvc.qryCurrentWeather.lastResult} /
!-- holds the extended weather --
mx:DataGrid visible=false height=50 width=50 
id=dgExtendedWeather 
dataProvider={weatherSvc.qryExtendedWeather.lastResult} /

mx:ViewStack x=5 y=-2 id=vsWeather width=483 
height=56 selectedIndex=0
mx:Canvas label=Current id=CurrentView 
width=493 height=58
mx:Label id=lbmylocid visible=false 
text={mylocID} /
mx:Label x=-3 y=-1 text=WEATHER 
id=WeatherLabel fontSize=13 fontWeight=bold color=#ff8000/
mx:Label id=conditions 
text={StandardDateFormat.format
(dgCurrentWeather.selectedItem.CurrentDate)} x=-1 y=18 
fontSize=11/
mx:Label x=-2 y=35 text=UV Index: 
{dgCurrentWeather.selectedItem.uvIndex} id=uvIndex 
color=#ff fontSize=11/
mx:Image x=141 y=2 id=WeatherIcon 
source=images/32x32/{dgCurrentWeather.selectedItem.icon} 
width=32 height=32/
mx:Label x=179 y=16 
text={dgCurrentWeather.selectedItem.temp} F id=temp 
fontWeight=bold fontSize=12/
mx:Label x=179 y=33