<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" backgroundGradientColors="[#ffffff, #ffffff]" creationComplete="init();" viewSourceURL="">
<mx:Style source="style.css" />
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
[Bindable]
public var _unit:String = 'c';
public var _xmlBlock:XML;
public var _link:String;
public var _userId:String;
public var _defaultLocation:String;
private function init():void
{
RO.populateCombo();
}
private function handleCombo(event:ResultEvent):void
{
locationCombo.dataProvider = event.result;
}
private function handleForecast(event:ResultEvent):void
{
_xmlBlock = XML(event.result);
var labelText:String = _xmlBlock..item.title;
returnLabel.text = labelText
var link:String = _xmlBlock..channel.link;
_link = link
var desc:String = _xmlBlock..item.description;
returnDescription.htmlText = desc;
linkButton.enabled = true;
}
private function handleRadio(event:ItemClickEvent):void
{
if (event.currentTarget.selectedValue == "c")
{
_unit = 'c'
}
else {
_unit = 'f'
}
}
private function callForecast():void
{
RO.getForecast(locationCombo.selectedItem.data, _unit);
}
private function goToUrl():void
{
var url:URLRequest = new URLRequest(_link);
navigateToURL(url,"_blank");
}
]]>
</mx:Script>
<mx:RemoteObject destination="ColdFusion"
id="RO"
fault="Alert.show(event.fault.message)"
source="qnet2.cfc.remote.weather"
showBusyCursor="true">
<mx:method name="populateCombo" result="handleCombo(event)" fault="Alert.show(event.fault.message)"/>
<mx:method name="getForecast" result="handleForecast(event)" fault="Alert.show(event.fault.message)"/>
</mx:RemoteObject>
<mx:Canvas x="10" y="10" width="450" height="529">
<mx:Label x="10" y="10" text="My Weather" id="headerLabel"/>
<mx:ComboBox x="103" y="38" id="locationCombo" change="callForecast()" prompt="Select Location"></mx:ComboBox>
<mx:RadioButtonGroup id="unit" itemClick="handleRadio(event);"/>
<mx:RadioButton groupName="unit"
id="Celsius"
value="c"
label="Celsius"
x="103" y="67"
selected="true"/>
<mx:RadioButton groupName="unit"
id="Fahrenheit"
value="f"
label="Fahrenheit"
x="185" y="67" />
<mx:Label x="10" y="122" id="returnLabel"/>
<mx:Button x="10" y="497" id="linkButton" label="Full Forecast" click="goToUrl()" enabled="false"/>
<mx:Text x="10" y="40" text="Select a location"/>
<mx:Text x="10" y="67" text="Units"/>
<mx:TextArea x="10" y="152" width="375" height="337" id="returnDescription" borderStyle="none" editable="false"/>
</mx:Canvas>
</mx:Application>