From a55c3e2ed7c3f2b3f82378c203b49334fa52890e Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 19 Feb 2010 22:30:55 -0500 Subject: [PATCH] adding example for item renderers, modified with sanified separation --- 03d2-item-renderers/HBoxWeatherDisplay.mxml | 31 +++++++++++ 03d2-item-renderers/WeatherApp.as | 57 +++++++++++++++++++++ 03d2-item-renderers/WeatherDisplay.mxml | 45 ++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 03d2-item-renderers/HBoxWeatherDisplay.mxml create mode 100644 03d2-item-renderers/WeatherApp.as create mode 100644 03d2-item-renderers/WeatherDisplay.mxml diff --git a/03d2-item-renderers/HBoxWeatherDisplay.mxml b/03d2-item-renderers/HBoxWeatherDisplay.mxml new file mode 100644 index 0000000..3b91ba2 --- /dev/null +++ b/03d2-item-renderers/HBoxWeatherDisplay.mxml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/03d2-item-renderers/WeatherApp.as b/03d2-item-renderers/WeatherApp.as new file mode 100644 index 0000000..8baa284 --- /dev/null +++ b/03d2-item-renderers/WeatherApp.as @@ -0,0 +1,57 @@ +package +{ + import mx.collections.ArrayCollection; + import mx.controls.TextInput; + import mx.core.Application; + import mx.rpc.events.ResultEvent; + import mx.rpc.http.HTTPService; + + public class WeatherApp extends Application + { + + function WeatherApp() + { + } + + [Bindable] + public var myResult:XML; + + [Bindable] + public var weatherObject:Object; + + [Bindable] + public var listContents:ArrayCollection; + + public var weatherService:HTTPService; + public var zip:TextInput; + + public namespace yweather = "http://xml.weather.yahoo.com/ns/rss/1.0"; + use namespace yweather; + + public function requestWeather():void { + weatherService.cancel(); + var params:Object = new Object(); + params.p = zip.text; + weatherService.send(params); + } + + public function resultHandler(event:ResultEvent):void { + myResult = XML(event.result); + weatherObject = new Object(); + weatherObject.zip = zip.text; + weatherObject.city = myResult.channel.yweather::location.@city; + weatherObject.temp = myResult.channel.item.yweather::condition.@temp; + weatherObject.imgsource = parseImageUrl(myResult.channel.item.description); + + var a:Array = new Array(weatherObject); + listContents = new ArrayCollection(a); + } + + public function parseImageUrl(fromHtml:XMLList):String { + var pattern:RegExp = /img src="(.+?)"/; + var results:Array = pattern.exec(fromHtml); + var imageURL:String = results[1]; // backreference 1 from pattern + return imageURL; + } + } +} diff --git a/03d2-item-renderers/WeatherDisplay.mxml b/03d2-item-renderers/WeatherDisplay.mxml new file mode 100644 index 0000000..e7218f3 --- /dev/null +++ b/03d2-item-renderers/WeatherDisplay.mxml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +