0 Replies - 4153 Views - Last Post: 26 October 2011 - 12:04 AM

#1 ralzari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 18-October 10

Daylight Saving Reading Clock Values from URL

Posted 26 October 2011 - 12:04 AM

Hi All,

I have written this analog daylight saving actionscript that picks the clock values from a service provider that offers API www.worldweatheronline.com. I have developed this for our internal portal. When i place the .swf on the server and open the portal, it seems working fine for about 5 minutes then it stops updating the clocks.

Any suggestions? I would appreciate anyone's help in this.


// import the Delegate class
import mx.utils.Delegate;

// hide clock elements whilst initial loading of data occurs
_root.AMPM._alpha=0
_root.hour._alpha=0
_root.sec._alpha=0
_root.min._alpha=0
	
var customLocation:String = "atlanta";

// key required by provider http://www.worldweatheronline.com/time-zone-api.aspx?q=new-york
// example
// http://www.worldweatheronline.com/feed/tz.ashx?key=891eb9dea1105418111108&q=manama

// supplied by HTML FlshVars
var key:String="891eb9dea1105418111108";

// declare a new XML instance
var timedata:XML = new XML();

// Once XML file has been loaded, grab node with time and date
// for parsing and pass to renderTime()
function onXmlLoaded(success:Boolean) {
   if (success) {
      // do whatever you want to do if the XML file was read successfully
      // use peoplexml.firstChild to access the main node
	  // make a handle to the root node in the xml
      var timeNode:XMLNode = timedata.firstChild

	  // in format; 2011-08-11 15:07
	  var time:String = timeNode.childNodes[1].childNodes[0].firstChild;
	  
	  //<data>
	  //	<request>
	  //		<type>City</type>
	  //		<query>Manama, Bahrain</query>
	  //	</request>
	  //	<time_zone>
	  //		<localtime>2011-08-11 14:09</localtime>
	  //		<utcOffset>3.0</utcOffset>
	  //	</time_zone>
	  //</data>
	  
      //update = mainnode.attributes.lastupdate; 
	  
	  RenderTime(time);

   } else {
      // do whatever you want to do if an XML read error occurred
   }
}

// for a string representation of time, render clock face
function RenderTime(time){
	var Time:String = new String(time);
	var _hours:String = new String();
	var _minutes:String = new String();
	_hours = Time.substr(11,2)
	_minutes = Time.substr(14,2);

	var hours = parseInt(_hours)
	var minutes = parseInt(_minutes)
	
	if(hours < 12){
		_root.AMPM.gotoAndStop(1);		
	}else{
		_root.AMPM.gotoAndStop(2);
	}
	_root.AMPM._alpha=100
	_root.hour._alpha=100
	_root.min._alpha=100
	
	//seconds = seconds*6; // calculating seconds

	// convert minutes to degrees
	minutes = minutes*6; 

	// convert hours to degrees
	hours = hours*30; 

	// no second hand as per design visuals
	sec._visible=false
	//sec._rotation=seconds; // giving rotation property
	min._rotation=minutes; // giving rotation property
	hour._rotation=hours; // giving rotation property

	trace(hours)	
	trace(time)
	
}


function getTimeFromFeed() {
   // ignore tabs, returns, and other whitespace between nodes
   timedata.ignoreWhite = true;	

   // set the scope of the onload function to the main timeline, not peoplexml
   timedata.onload = Delegate.create(this, onXmlLoaded);
	
   // start loading the file
   timedata.load("http://www.worldweatheronline.com/feed/tz.ashx?key=891eb9dea1105418111108&q=atlanta");	   
}

// COMMENT THIS OUT WHEN RUNNING LOCALLY
// try and get location from paramters as specified by FlashVars on
// page with movie embedded
try 
{    
	customLocation = _root.location
	//key = _root.providerkey
	
} 
catch (error:Error) 
{
    customLocation = "atlanta"
}

// set location as specified by Flashvars in HTML where movie is embedded
//_root.test.text = customLocation;


// get Time on first load
getTimeFromFeed();

// get Time every 30 seconds from feed
var intID:Number = setInterval(getTimeFromFeed, 30); // 





Is This A Good Question/Topic? 0
  • +

Page 1 of 1