flash rss 天气预报源码

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

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

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


flash rss 天气预报源码



下面是源码,可直接编成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));

*/


你可能感兴趣的:(JavaScript,linux,OS,Google,Flash)