`
wuzijingaip
  • 浏览: 329954 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

flash rss 天气预报源码

阅读更多
最简单的flash rss 天气预报源码,注:flash发布分为只访问网络和只访问本地,这个当然要设为只访问网络,不然会有提示框弹出

本例是用 Flash 8 工具( ActionScrtipt2.0 ) 写的  

第二个包包含第一个并完善一点点(如有多个,以此类推)
第二个包运行载图:






下面是源码,可直接编成swf 文件运行

//fscommand("showmenu", "false");
//fscommand("fullscreen", "true");
//fscommand("wmode","transparent");
fscommand("scale","exactfit");
Stage.scaleMode = "exactfit";//Stage.scaleMode = "noScale";

var param_city_cn = "广州";
var city = "guangzhou,guangdong";
var language = "zh-cn";

var weather_msg_logo_arr = [
							"晴,0"
							,"以晴为主,0"
							, "雾,2"
							,"雾霾,2"
							, "多云,3"
							, "阴,4"
							,"可能有暴风雨,9"
							, "可能有雨,6"
							, "晴间多云,3"
							, "阴-雷-雨,6" 
							, "雨,9"
							, "雷-雨,10"
							, "阴-雨,5"
							, "晴-阴,2"
							, "雨-,9"
							,"Chance of Rain,6"
							,"Chance of Storm,9"
							,"Cloudy,3"
							,"Partly Sunny,3"
							,"Fog,2"
							,"Light rain,6"
							,"rain,9"
							];


//var flash = new SWFObject('xml1.swf', 'mymovie', 800, 400, '7', '');
var param_color1 = 0xffffff;
var param_color2 = 0x2f6da6;
var param_size1 = 20;
var param_size2 = 16;
var param_city = "guangzhou,guangdong";
var imdex = 0;
var count = 0;
var getUrlStr = "";
var next_day_low = "";
var next_day_high = "";
var next_day_weather = "";
var next_day_low2 = "";
var next_day_high2 = "";
var next_day_weather2 = "";

picW = 20;
picH = 80;
link1 = "link";
//city = "xiangfan,hubei";
//http://www.google.com/ig/api?weather=xiangfan,hubei&hl=zh-cn
var first_url = "http://www.google.com";
var url = first_url+"/ig/api?weather="+city+"&hl=" + language;

var lowstr = "";
var highstr = "";
var weatherstr = "";
var timestr = "";
var weekstr = "";
var shidustr = "";
var windstr = "";
var citystr = "";
var shengstr = "";
var datestr = "";

var current_week = "";
var next_week = "";
var next_week2 = "";

var main:MovieClip = this;


/*
var myXML = new XML();

fpv_cn = new LoadVars();
fpv_cn.load(url);

fpv_cn.onData = function(data) {
	fpv_cn_str = new String(data);
	//trace(fpv_cn_str);
	myXML = new XML(fpv_cn_str);
		_root.createEmptyMovieClip(loadPic, -1000);
		
		_root[loadPic]._y = 20;
		showWeather();
}*/


var myXML = new XML();
myXML.ignoreWhite = true;
//trace(url);
myXML.load(url);
myXML.onLoad = function(success) {
	if (success) {
		_root.createEmptyMovieClip(loadPic, -1000);
		
		_root[loadPic]._y = 20;
		showWeather();
	} else {
		trace("加载不成功");
	}
};

var interval ;
var intervalCount = 0;

function reLoadMsg(){
	
	if(intervalCount > 3){
		myXML = new XML("http://www.google.com/ig/api?weather=guangzhou,guangdong&hl=zh-cn");
		showWeather();
	}else{
		
		if(count  <= 1){
			interval = setInterval(showWeather,1000);
		}
	}
}

var systemmsg = "";
//检测操作系统
var os:String = System.capabilities.os.substr(0, 3);
systemmsg += os+"   ";
//检查播放器类型
var playertype:String = System.capabilities.playerType;
//tips.text = playertype;
if (playertype == 'External') {
	System.useCodepage = true;
} else if (playertype == 'StandAlone') {
	System.useCodepage = true;
} else if (playertype == 'Plugin' || playertype == 'PlugIn') {
	System.useCodepage = false;
} else {
	System.useCodepage = false;

}
if(language == 'zh-hk'){
	System.useCodepage = false;
}

//检测系统语言
var lang:String = System.capabilities.language;
systemmsg += playertype+"   "+lang;
/*
    //检测屏幕分辨率
    var screenx:int=System.capabilities.screenResolutionX;
    var screeny:int=System.capabilities.screenResolutionY;
    var screencolor=System.capabilities.screenColor;
   trace(lang+"   "+screenx+"   "+screeny+"   "+screencolor);
   */
function changeWeatherLogo(obj, index) {
	obj.gotoAndPlay(index);
}
function checkWeatherMsg(obj, checkMsg) {
	var index = getWeatherLogoIndex(checkMsg);
	//trace(obj+'   '+checkMsg+'   '+index);
	changeWeatherLogo(obj, index);
}
function getWeatherLogoIndex(checkMsg) {
	var index = 1;
	for (var i = 0; i<weather_msg_logo_arr.length; i++) {
		var msg = weather_msg_logo_arr[i].split(',')[0];
		index = weather_msg_logo_arr[i].split(',')[1];
		if (msg.indexOf("-") != -1) {
			var ls_msgs = msg.split("-");
			var all_true = true;
			for (var j = 0; j<ls_msgs.length; j++) {
				if (checkMsg.indexOf(ls_msgs[j]) == -1) {
					all_true = false;
				}
			}
			if (all_true) {
				return index;
			}
		} else {
			if (checkMsg == msg) {
				return index;
			}
		}
	}
}

String.prototype.replace = function(oldStr:String, newStr:String) {
 return this.split(oldStr).join(newStr); 
}
function sFilter(str,reg){
	return str.replace('可能有','').replace("Chance of",'');
}
function shiduFilter(str){
	var s = "湿度";
	if(language == 'zh-hk'){
		s = "濕度";
	}
	return s + ":" + str.split(" ")[1];
}

function weekFilter(str){
	return str.replace("周","星期").replace("週","星期");
}
/*******************************/
function showWeather() {
	var showstr = "";
	var imgstr = "";
	myList = myXML.firstChild.firstChild.childNodes;
	count = myList.length;
	
	//trace(count+'   '+myList);
	for (i=0; i<myList.length; i++) {
		imdex = i;
		var dayMsg = myList[i].childNodes;
		for (j=0; j<dayMsg.length; j++) {
			if (i == 0) {
				citystr = dayMsg[0].attributes.data.split(",")[0];
				datestr = dayMsg[4].attributes.data;
			}
			if (i == 1) {
				shidustr = dayMsg[3].attributes.data;
				windstr = dayMsg[5].attributes.data;
			}
			if (i == 2) {
				current_week = dayMsg[0].attributes.data;
				lowstr = dayMsg[1].attributes.data;
				highstr = dayMsg[2].attributes.data;
				imgstr = dayMsg[3].attributes.data;
				weatherstr = dayMsg[4].attributes.data;
				checkWeatherMsg(current_day_logo, weatherstr);
			}
			if (i == 3) {
				next_week = dayMsg[0].attributes.data;
				next_day_low = dayMsg[1].attributes.data;
				next_day_high = dayMsg[2].attributes.data;
				next_day_weather = dayMsg[4].attributes.data;
				checkWeatherMsg(next_day_logo, next_day_weather);
			}
			if (i == 4) {
				next_week2 = dayMsg[0].attributes.data;
				next_day_low2 = dayMsg[1].attributes.data;
				next_day_high2 = dayMsg[2].attributes.data;
				next_day_weather2 = dayMsg[4].attributes.data;
				checkWeatherMsg(next_day_logo2, next_day_weather2);
			}
		}
	}
	showWeatherMsg();
	var showImgUrl = first_url+imgstr;
}

function showWeatherMsg() {
	//var weatherText_ms = _root[LoadPic].createEmptyMovieClip("weatherText_ms", 80);
	//var dateText_ms = _root[LoadPic].createEmptyMovieClip("dateText_ms", 1);
	//var city_ms = _root[LoadPic].createEmptyMovieClip("city_ms", 50);
	//var next_day_ms = _root[LoadPic].createEmptyMovieClip("next_day_ms", 2);
	//var next_day_ms2 = _root[LoadPic].createEmptyMovieClip("next_day_ms2", 3);
	
	shidu_ms.createTextField("shidumsg",1,0,0,200,100);
	
	dateText_ms.createTextField("datemsg", 1, 0, 0, 300, 100);
	//日期
	weatherText_ms.createTextField("windmsg", 0, 0, 0, 300, 100);
	//当天风速
	current_temp.createTextField("temperaturemsg", 2, 0, 0, 300, 100);
	//当天温度
	city_ms.createTextField("citymsg", 3, 0, 0, 300, 100);
	//城市信息
	current_weather.createTextField("weathermsg", 5, 0, 0, 300, 100);
	//当天天气
	
	
	nextdayTitle_ms.createTextField("nextdayTitle", 4, 0, 0, 200, 100);
	nextdayTitle_ms2.createTextField("nextdayTitle2", 4, 0, 0, 200, 100);
	nextdaytem_ms.createTextField("nextdaytem", 5, 0, 0, 200, 100);
	//第二天温度
	nextdaytem_ms2.createTextField("nextdaytem2", 5, 0, 0, 200, 100);
	//3td
	nextdayweather_ms.createTextField("nextdayweather", 6, 0, 0, 200, 100);
	//第三天温度
	nextdayweather_ms2.createTextField("nextdayweather2", 6, 0, 0, 200, 100);
	//3td
	nextdayTitle_ms.nextdayTitle.text = weekFilter(next_week);
	nextdayTitle_ms2.nextdayTitle2.text = weekFilter(next_week2);
	nextdaytem_ms.nextdaytem.text = next_day_low+" / "+next_day_high+"℃";
	nextdayweather_ms.nextdayweather.text = sFilter(next_day_weather);
	nextdaytem_ms2.nextdaytem2.text = next_day_low2+" / "+next_day_high2+"℃";
	nextdayweather_ms2.nextdayweather2.text = sFilter(next_day_weather2);
	current_weather.weathermsg.text = sFilter(weatherstr);
	shidu_ms.shidumsg .text = shiduFilter(shidustr);
	//设置文字样式
	dateText_ms.datemsg.text = datestr + " "+ weekFilter( current_week);
	//设置文字样式
	current_temp.temperaturemsg.text = lowstr+" / "+highstr+"℃";
	//设置文字样式
	//weatherText_ms.windmsg.text = windstr;
	//设置文字样式
	citystr = param_city_cn;
	city_ms.citymsg.text = citystr;
	//设置文字样式
	
	
	textstyle1 = new TextFormat();
	textstyle1.color = param_color1;
	textstyle1.font = "verdana";
	textstyle1.size = param_size1;
	textstyle1.bold = true;
	
	textstyle2 = new TextFormat();
	textstyle2.color = param_color2;
	textstyle2.font = "verdana";
	textstyle2.size = param_size2;
	textstyle2.bold = true;
	
	textstyle3 = new TextFormat();
	textstyle3.color = param_color1;
	textstyle3.font = "arial";
	textstyle3.size = 20;
	textstyle3.bold = true;
	
	current_temp.temperaturemsg.setTextFormat(textstyle3);
	dateText_ms.datemsg.setTextFormat(textstyle1);
	current_weather.weathermsg.setTextFormat(textstyle3);
	shidu_ms.shidumsg.setTextFormat(textstyle3);
	city_ms.citymsg.setTextFormat(textstyle1);
	nextdayTitle_ms.nextdayTitle.setTextFormat(textstyle2);
	nextdayTitle_ms2.nextdayTitle2.setTextFormat(textstyle2);
	nextdaytem_ms.nextdaytem.setTextFormat(textstyle2);
	nextdayweather_ms.nextdayweather.setTextFormat(textstyle2);
	nextdaytem_ms2.nextdaytem2.setTextFormat(textstyle2);
	nextdayweather_ms2.nextdayweather2.setTextFormat(textstyle2);
}

function alert(msg){
	trace(msg );
}

/*************************/
/*
var os:String = System.capabilities.os.substr(0, 3);
if (os == "Win") {
// Windows-specific code goes here
} else if (os == "Mac") {
// Mac-specific code goes here
} else {
// Must be Unix or Linux
}

if(flash.system.Capabilities.playerType == "Plugin") {
// do actions for Mozilla, etc. browsers
}
else if(flash.system.Capabilities.playerType == "ActiveX") {
// do actions for IE
}
else {
// do actions for no browser
}

检测系统语言

// Example output: en-US
trace(flash.system.Capabilities.language);
var greetings:Array = new Array( );
greetings["en"] = "Hello";
greetings["es"] = "Hola";
greetings["fr"] = "Bonjour";
var lang:String = flash.system.Capabilities.language.substr(0, 2);
if (greetings[lang] == undefined) {
lang = "en";
}

利用分辨率还可以居中你的弹出窗口:
var resX:int = flash.system.Capabilities.screenResolutionX;
var resY:int = flash.system.Capabilities.screenResolutionY;
//设置窗口的宽和高
var winW:int = 200;
var winH:int = 200;
// 设置窗口起始坐标
var winX:int = (resX / 2) - (winW / 2);
var winY:int = (resY / 2) - (winH / 2);
// 创建代码,然后传递给URLLoader.load( )
// 打开新浏览器窗口
var jsCode:String = "javascript:void(
newWin=window.open('http://www.person13.com/'," +
"'newWindow', 'width=" + winW +
", height=" + winH + "," +
"left=" + winX + ",top=" + winY + "'));";
// 使用URLLoader 对象调用JavaScript 函数
urlLoader.load(new URLRequest(jsCode));

*/


  • 大小: 55.3 KB
分享到:
评论
2 楼 dream0o 2011-03-03  
有一个问题,flash不能实时更新,要重新点开flash才能更新文档
1 楼 dream0o 2011-03-03  
为什么找不到xml文件?是否有一个文件没加进去?

相关推荐

    flash rss 天气预报

    “源码”标签表明该压缩包可能包含了实现这个Flash RSS天气预报应用的ActionScript代码,ActionScript是Flash编程所使用的脚本语言。而“工具”标签可能意味着博主分享了创建这个项目时用到的一些工具或资源,例如...

    Rss全国各省市天气预报

    【Rss全国各省市天气预报】项目是一个利用RSS(Really Simple Syndication)技术获取并解析全国各地天气信息的应用。RSS是一种基于XML的格式,用于发布和订阅新闻、博客、天气等实时信息,使得用户能轻松地获取和...

    google地图Rss天气预报订阅

    在google地图上面实现天气预报订阅!

    ASP.NET程序中使用Yahoo的天气RSS实现天气预报功能源代码

    标题提到的“Yahoo的天气RSS实现天气预报功能”涉及到RSS(Really Simple Syndication)技术。RSS是一种内容发布格式,允许用户订阅和获取网站更新,如新闻、博客或天气预报等。Yahoo提供了一个公开的天气RSS feed,...

    一个基于新浪RSS的android RSS阅读器源码

    《基于新浪RSS的Android RSS阅读器源码解析与学习指南》 RSS(Really Simple Syndication)是一种内容聚合格式,常用于新闻、博客等网站,让用户能够方便地获取和订阅更新内容。在移动设备上,RSS阅读器应用是访问...

    android rss阅读器源码

    【Android RSS阅读器源码详解】 RSS(Really Simple Syndication)是一种内容聚合格式,常用于新闻、博客等网站,使得用户可以订阅并获取最新的更新内容。Android RSS阅读器源码是一个专门为Android平台设计的应用...

    中国城市代码天气预报(yahoo RSS)

    当用到雅虎的Rss天气服务时会用到。 阿巴嘎旗  CHXX0243  阿城 CHXX0001  爱辉 CHXX0174  阿合奇 CHXX0210  阿拉尔 CHXX0212  阿勒泰 CHXX0196  安达  CHXX0187  敖汉旗 CHXX0002  安康  CHXX0394  安宁...

    C# RSS阅读器源码

    【C# RSS阅读器源码】是一个初学者项目,展示了如何使用C#语言来实现一个基本的RSS新闻订阅工具。RSS(Really Simple Syndication)是一种数据格式,常用于发布新闻、博客和其他定期更新的内容,使得用户可以方便地...

    新浪RSS 阅读器 android源码

    源码分析有助于开发者理解RSS订阅和解析的过程,以及如何在Android环境下构建一个功能完善的新闻阅读应用。以下是对该源码中涉及的关键知识点的详细说明: 1. **RSS(Really Simple Syndication)**: RSS是一种XML...

    web版Rss阅读器源码

    Web版RSS阅读器源码是基于网页的订阅工具,它允许用户从各种RSS(Really Simple Syndication)源获取和阅读新闻、博客文章等更新。在本文中,我们将深入探讨RSS阅读器的工作原理、关键技术以及如何使用Java实现这样...

    Android RSS阅读器的源码.rar

    《Android RSS阅读器源码解析》 在移动开发领域,Android平台因其开源、灵活的特点,深受开发者喜爱。本文将深入探讨一个基于Android的RSS阅读器的源码,旨在帮助开发者理解RSS阅读器的工作原理,提升Android应用...

    java实现天气预报(解释+源代码)

    ### Java实现天气预报客户端 #### 一、引言 随着互联网技术的发展,越来越多的数据和服务以API的形式对外开放。其中,天气预报作为一个重要的生活信息来源,被广泛应用于各类应用场景中。本文将详细介绍如何使用...

    Rss阅读器源码.net实现C#编写

    本项目“Rss阅读器源码.net实现C#编写”提供了完整的源代码,使开发者可以深入理解RSS阅读器的工作原理,并能根据需要进行定制或二次开发。 首先,C#是微软开发的一种面向对象的编程语言,常用于构建Windows桌面...

    Android Rss订阅源码Demo.zip

    这个"Android Rss订阅源码Demo.zip"是一个实用的示例项目,可以帮助开发者了解如何在Android应用中实现RSS订阅功能。 1. **RSS基础概念**: RSS是一种XML格式,用于发布和共享信息,通常用于博客、新闻站点等。它...

    RSS阅读器的源码

    【RSS阅读器的源码】是一个基于Android平台的应用程序,主要功能是允许用户手动更新RSS(Really Simple Syndication)新闻源。RSS是一种订阅式的互联网内容发布格式,它使得用户能够轻松跟踪并聚合多个网站的更新...

    史上最齐全的RSS阅读器源码

    史上最齐全的RSS阅读器源码 使用了ASP.NET 运用到Ajax的页面不刷新 各种源码 方便学习

    iOS-RSS阅读器源码

    "iOS-RSS阅读器源码"是开发者或者学习者研究iOS应用开发,特别是RSS解析和显示技术的宝贵资源。下面我们将详细探讨这个源码可能包含的知识点和相关的开发技术。 1. **Swift或Objective-C编程**:iOS应用通常使用...

Global site tag (gtag.js) - Google Analytics