In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

yahoo!pipesで天気テスト

Get Adobe Flash player
by HaraMakoto 08 Aug 2009
/**
 * Copyright HaraMakoto ( http://wonderfl.net/user/HaraMakoto )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/eOu3
 */

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	[SWF(width = "465", height = "465", frameRate = "30", backgroundColor="0x000000")]
	public class weathertest extends Sprite
	{
		private var txtField:TextField = new TextField();
		private var urlLoader:URLLoader = new URLLoader;
		private var wXML:XML;
		
		//最高、最低、天気
		private var max:String;
		private var min:String;
		private var wed:String;
		
		public function weathertest()
		{
			addChild(txtField);
			txtField.width=300;
			txtField.height=500;
			txtField.textColor = 0xFFFFFF;
			txtField.x = txtField.y = 50;
			ldLoad();
		}
		
		private function ldLoad():void
		{
			urlLoader.load(new URLRequest("http://pipes.yahooapis.com/pipes/pipe.run?_id=c2e1d75103bdbf5799d5fbd3cf1f7bb6&_render=rss"));
			urlLoader.addEventListener(Event.COMPLETE, compHandler);
		}
		
		private function compHandler(e:Event):void
		{
			wXML = new XML(urlLoader.data);
			var todayString:String = wXML.channel.item[1].description;
			//max = todayString.split("最高気温は")[1];
			//max = max.split("℃")[0];
			//var min:String = todayString.split("最低気温は")[1];
			//min = min.split("℃")[0];
			
			if( !todayString.split("最高気温は")[1] ) {
				max = "--"
			} else {
				max = todayString.split("最高気温は")[1];
				max = max.split("℃")[0];
			}
			if(!todayString.split("最低気温は")[1]) {
				min = "--";	
			} else {
				min = todayString.split("最低気温は")[1];
				min = min.split("℃")[0];
			}
			var todayWed:String = todayString.split("天気は")[1];
			switch(todayWed.substr(0,1)) {
				case("晴"):
				 wed="shine";
				 break;
				case("雨"):
				 wed="rain";
				 break;
				case("曇"):
				 wed = "cloud"
				 break;
			}
			
			var s:String="";
			s += "今日の東京は\n";
			s += "最高気温"+max+"度\n";
			s+= "最低気温"+min+"度\n";
			s+="天気は"+todayWed.substr(0,1);
			txtField.text = s;
		}
		
		

	}
}