flash制作天气预报

最开始想用google的weather api,http://www.google.com/ig/api?weather=shanghai,做到最后,本地实现了,但传上去发现google并不允许flash跨域读取xml,没办法,只能另外寻找合适的xml数据源。yahoo weather 也有提供api,http://weather.yahooapis.com/forecastrss?w=2151849&u=c,但是实用数据全部以html的格式放在xml中,无法自定义样式,所以也只能作罢。 Read More

attachments/month_0801/p200813101551.swf
flash中支持的CSS 属性是很有限的,并不能做到像html中那样自由。[quote]text-align 可以识别的值包括 left、center、right 和 justify。
font-size 只使用该值的数字部分。不分析单位(px、pt);像素和磅是等价的。
text-decoration 可以识别的值包括 none 和 underline。
margin-left 只使用该值的数字部分。不分析单位(px、pt);像素和磅是等价的。
margin-right 只使用该值的数字部分。不分析单位(px、pt);像素和磅是等价的。
font-weight可以识别的值包括 normal 和 bold。
kerning 可以识别的值包括 true 和 false。
font-style 可以识别的值包括 normal 和 italic。
letterSpacing 只使用该值的数字部分。不分析单位(px、pt);像素和磅是等价的。
text-indent 只使用该值的数字部分。不分析单位(px、pt);像素和磅是等价的。
font-family 用逗号分隔的供使用字体的列表,按需求降序排列。可以使用任何字体系列名称。如果您指定通用字体名称,则它将转换为相应的设备字体。支持以下字体转换:mono 转换为 _typewriter、sans-serif 转换为 _sans 以及 serif 转换为 _serif。
color 只支持十六进制颜色值。不支持命名的颜色(如 blue)。颜色以下面的格式写入:#FF0000。[/quote]
AS如下:[code]var my_css = new TextField.StyleSheet();
my_css.onLoad = function(success) {
if (success) {
my_txt.styleSheet = my_css;
var my_lv = new LoadVars();
my_lv.onLoad = function(success) {
if (success) {
my_txt.html = true;
my_txt.htmlText = this.myText;
}
};
my_lv.load("http://And8.net/files/flash/LoadVars/text1.txt");
}
};
my_css.load("http://And8.net/files/flash/LoadVars/mycss1.css");[/code]
CSS如下:[quote]h1{font-size:18px;font-weight:bold; text-align:center; color:#00CC00;}
.from{text-align:right; font-family:04b_03; font-size:8px; color:#ffcc00;}
a{color:#ffcc00}
a:hover{color:#ff0000}[/quote]
TXT文本如下:

myText=

关于火棘的介绍

FROM:AND8.NET

长绿灌木,高达3米,侧枝短,顶端呈刺状,小枝有时有锈色绒毛,老时无毛。叶片倒卵形或倒卵状长圆形。分布浙江,福建,湖北,湖南,广西,陕西,四川,贵州,云南,西藏等省区。

xml图片背景菜单

attachments/month_0801/42008131055.swf
放大的:/attachments/month_0801/42008131055.swf
[code]var my_XML = new XML();
my_XML.ignoreWhite = true;
my_XML.onLoad = function(success) {
if (success) {
funMenu();
}
};

my_XML.load("/files/flash/xml/menu1.xml");

function funMenu() {
var menuItem = my_XML.firstChild.childNodes;
for (i=0; i<menuItem.length; i++) {
var tempClip = attachMovie("button_clip", "button"+i, 100+i, {_y:37});
tempClip._x = 60+119*i;
tempClip.button_txt.text = menuItem[i].attributes.title;
tempClip.url = menuItem[i].attributes.url;
funButton(tempClip);
}
}

function funButton(nButton) {
nButton.onRelease = function() {
getURL(this.url, "_blank");
};
nButton.onRollOver = function() {
this.onEnterFrame = function() {
if (this._currentFrame != this._totalFrames) {
this.nextFrame();
} else {
delete this.onEnterFrame;
}
};
};
nButton.onRollOut = nButton.onDragOut=function () {
this.onEnterFrame = function() {
if (this._currentFrame != 1) {
this.prevFrame();
} else {
delete this.onEnterFrame;
}
};
};
}[/code]
XML内容如下:[code]<?xml version="1.0" encoding="UTF-8"?>
<menu>
<item title="And8.net" url="http://And8.net"/>
<item title="Ebailu.com" url="http://www.Ebailu.com"/>
<item title="DaShuLin.com" url="http://DaShuLin.com"/>
</menu>[/code]

xml图片展示

xml图片展示,没有加preloader,可能要稍微一点等待时间。
XML文件:http://And8.net/files/flash/album/album.xml
放大的 /attachments/month_0712/420071228173846.swf
attachments/month_0712/420071228173846.swf
[code]var my_XML = new XML();
my_XML.ignoreWhite = true;
my_XML.onLoad = function(success) {
if (success) {
createAlbum();
}
};
my_XML.load("http://And8.net/files/flash/album/album.xml");

function createAlbum() {
var picture = my_XML.firstChild.childNodes;
for (i=0; i<picture.length; i++) {
var temp_mc =album_mc.createEmptyMovieClip("temp_mc"+i, i);
temp_mc._x = i*58+8;
temp_mc._y = 8;
temp_mc.createEmptyMovieClip("thumbnalis_temp",0);
temp_mc.thumbnalis_temp.loadMovie(picture[i].attributes.thumbnails);
temp_mc.thumbnails = picture[i].attributes.thumbnails;
temp_mc.description = picture[i].attributes.description;
temp_mc.image = picture[i].attributes.image;
temp_mc._alpha=70;
temp_mc.onRelease=function() {
picture_mc.loadMovie(this.image);
description_mc.description_txt.text=this.description;
};
temp_mc.onRollOver=temp_mc.onDragOver=function() {
this._alpha=100;
}
temp_mc.onRollOut=temp_mc.onDragOut=function() {
this._alpha=70;
}
}
}[/code]

xml信息内容展示

本例用到的xml是本站的rss源,因此,这个例子其实就是一个blog阅读器了。没有加preloader,xml文件有点大,可能需要稍微等待几秒钟。这个例子与上次flex的那个blog阅读器相比要复杂一些,但毕竟这个可以自己设定很多样式。
【可以看这个放大的】/attachments/month_0712/52007122719345.swf

attachments/month_0712/52007122719345.swf
[code]var my_XML = new XML();
my_XML.ignoreWhite = true;
article_mc._visible = false;

my_XML.onLoad = function(success) {
if (success) {
creatNewsList();
}
};

my_XML.load("http://And8.net/feed.asp");

function creatNewsList() {
j = 0;
var item = my_XML.firstChild.firstChild.childNodes;
for (i=8; i<item.length; i++) {
var temp_mc = menu_mc.attachMovie("title_mc", "title_mc"+j, 100+i);
temp_mc._y = j*24;
j++;
temp_mc.title_txt.text = item[i].childNodes[1].firstChild.nodeValue;
temp_mc.time_txt.text = item[i].childNodes[4].firstChild.nodeValue;
temp_mc.title_button.title = item[i].childNodes[1].firstChild.nodeValue;
temp_mc.title_button.value = item[i].childNodes[6].firstChild.nodeValue;
temp_mc.title_button.url = item[i].childNodes[0].firstChild.nodeValue;
temp_mc.title_button.onRelease = showContent;
}
}

function showContent() {
menu_mc._visible = false;
article_mc._visible = true;
article_mc.article_txt.html = true;
article_mc.url_mc.url_txt.html = true;
article_mc.title_txt2.text = this.title;
article_mc.article_txt.htmlText = this.value;
article_mc.url_mc.url_txt.htmlText = "+this.url+"' target='_blank'>"+this.url+"";
}

article_mc.button_close.onRelease = function() {
menu_mc._visible = true;
article_mc._visible = false;
article_mc.title_txt2.text = "";
article_mc.article_txt.htmlText = "";
article_mc.url_mc.url_txt.htmlText = "";
};[/code]

通过MovieClipLoader类加载外部影片(A Teens的upside down的一个swf视频片段)。外部影片有487K,可能我的虚拟主机比较好,我测试的时候居然3秒钟就下好了。A Teens的歌很好听,顺便推荐一下。attachments/month_0712/p2007122195416.swf
[code]var loader_mcl = new MovieClipLoader();
var bytes_loaded = target.getBytesLoaded();
var bytes_total = target.getBytesTotal();
loader_mcl.addListener(this);

button_load.onRelease = function() {
startPreload("http://And8.net/files/flash/UpsideDown.swf");
};

function startPreload(url) {
loader_mcl.loadClip(url,container_mc);
}
function onLoadStart(target) {
attachMovie("preloaderAnim","preLoad_mc",100,{_x:240, _y:120});
}
function onLoadProgress(target, bytes_loaded, bytes_total) {
target.stop();
target._visible = false;
preLoad_mc.present_txt.text = Math.round(100*bytes_loaded/bytes_total)+"%";
}
function onLoadComplete(target) {
target.play();
target._visible = true;
preLoad_mc.removeMovieClip();
}[/code]
[quote]MovieClipLoader
此类用于实现在 SWF、JPEG、GIF 和 PNG 文件正被加载到影片剪辑中时提供状态信息的侦听器回调。若要使用 MovieClipLoader 功能,请使用 MovieClipLoader.loadClip() 代替 loadMovie() 或 MovieClip.loadMovie() 来加载 SWF 文件。

在您发出 MovieClipLoader.loadClip() 命令后,下列事件将按列出顺序发生:

在下载的文件的第一个字节写入硬盘后,调用 MovieClipLoader.onLoadStart 侦听器。
如果您已实现了 MovieClipLoader.onLoadProgress 侦听器,则在加载过程中调用它。注意:您可以在加载过程中随时调用 MovieClipLoader.getProgress()。
在下载的整个文件都写入硬盘后,调用 MovieClipLoader.onLoadComplete 侦听器。
在执行完下载的文件的第一帧动作后,调用 MovieClipLoader.onLoadInit 侦听器。
在调用 MovieClipLoader.onLoadInit 后,您可以设置属性、使用方法,还可与加载的影片进行交互。
如果文件未能完全加载,则调用 MovieClipLoader.onLoadError 侦听器。
[/quote]

Tween类和easing类

折腾了很久,还是有地方不明白。
attachments/month_0712/520071215111240.swf
[code]import mx.transitions.Tween;
_global.style.setStyle("color","0xCCCCCC");
var ease;
ease = mx.transitions.easing.Back;
ease = mx.transitions.easing.Bounce;
ease = mx.transitions.easing.Elastic;
ease = mx.transitions.easing.None;
ease = mx.transitions.easing.Regular;
ease = mx.transitions.easing.Strong;

function tweenPlay(easingClass, easingMethod, easingTime) {
var fun:Function = mx.transitions.easing[easingClass][easingMethod];
myTween = new Tween(myLogo, "_x", fun, 60, 420, easingTime, true);
}
button_play.onRelease = function() {
var tempClass = radioGroup1.selectedData;
var tempMethod = radioGroup2.selectedData;
var tempTime = radioGroup3.selectedData;
tweenPlay(tempClass,tempMethod,tempTime);
};[/code]
[quote]【导入和使用 Tween 类: 】
import mx.transitions.Tween;
import mx.transitions.easing.*;
new Tween(ball_mc, "_x", Elastic.easeOut, Stage.width, 0, 3, true);

【mx.transitions.easing 包提供了六个类来控制缓动:】
Back 一次在一端或两端扩展到过渡范围之外以提供轻微的溢出效果。
Bounce 完全在过渡范围的一端或两端内提供弹跳效果。弹跳次数与持续时间有关:持续时间越长,弹跳次数越多。
Elastic 提供一端或两端超出过渡范围的弹性效果。弹性量不受持续时间影响。
None 提供从开始到结尾的无任何减速或加速效果的相同的运动。该过渡通常也称为线性过渡。
Regular 在加速效果、减速效果或这两种效果的一端或两端提供更慢的运动。
Strong 在一端或两端提供很慢的运动。此效果类似于 Regular,但更为显著。

【mx.transitions.easing 包中的每个类都提供以下三个缓动方法:】
easeIn 在过渡的开始提供缓动效果。
easeOut 在过渡的结尾提供缓动效果。
easeInOut 在过渡的开始和结尾提供缓动效果。[/quote]

Page 1 of 1012345678...Last »