PDA

View Full Version : Wind Directional Rotation coding -- how?



Rebel Star
July 31st, 2008, 01:59 PM
I am working on an app that will display data gathered from a weather station. The data is placed in an external XML file that the Flash app pulls in once every 10 seconds. Currently, I am trying to get the compass display of wind direction to work (see attached .fla).

I know how to get data pulled in and how to get the wind degrees displayed in a dynamic text field, but right now I need to figure out how to get that variable (wind_degrees) translated into the compass that is in the attached .fla. I need to have the arrow rotate around the circumference of the compass to indicate the position on the compass that equals the number that comes back from the XML file for wind_degrees.

Here is the code contained in the .fla so far... But there's nothing for the rotation of the arrow as I'm not sure where to begin.

Thanks!


var navData:XML;

function GetWind(evt:Event = null):void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
loader.load(new URLRequest("http://www.lehiweather.com/weather/flash2.jsp"));

function onComplete(evt:Event):void {
try {
navData = new XML(evt.target.data);
trace(navData);
loader.removeEventListener(Event.COMPLETE, onComplete);
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);

var windDeg:String = navData.wind_degrees;

} catch (err:Error) {
trace("Could not parse loaded content as XML:\n" + err.message);
}
}

function onIOError(evt:IOErrorEvent):void {
trace("An error occurred when attempting to load the XML.\n" + evt.text);
}
}
GetWind(); // First time

var datarefreshTimer:Timer = new Timer(10000, 0);
datarefreshTimer.addEventListener(TimerEvent.TIMER , GetWind);
datarefreshTimer.start();

GrndMasterFlash
July 31st, 2008, 04:32 PM
var windDeg:String = navData.wind_degrees;

below that line place these lines and there you go!

var pointRot:Number = Number(windDeg);
windDirectional_mc.Pointer.rotation = pointRot;

:thumb2:

****added note****
setting up a tween that would transition from the pointers current location to the new pointRot would be a good idea!

Rebel Star
August 1st, 2008, 01:10 PM
Cool, thanks! That worked like a charm -- but I think you're right, a tween would look nicer. A lot smoother. I'll see if I can get it worked out today. Thanks again!