1401/090
Flash-数据库数据的读取

由于一些原因,需要将一些数据以Flash的形式输出调用,所以就做了这么一个Demo,点这里看一下。
其中New Post是WordPress的日志,Guestbook和Wish Sky的调用基本相同,
SO,这里只讲下WordPress的部分。
先是Flash部分代码:
//导入tweenlite
import gs.TweenLite;
import gs.easing.*;
//xml载入处理部分
var xml_news:XML = new XML();
xml_news.ignoreWhite = true;
xml_news.onLoad = function(s:Boolean) {
if (s) {
trace("xml loaded");
newsxmlroot = xml_news.firstChild;
newsxmllen = newsxmlroot.childNodes.length;
initNews(mc_loader);
} else {
trace("xml load failed");
}
};
//因为我是输出到qzone,这里必须得写xml文件的绝对物理路径。
xml_news.load("http://nwhy.org/nwhy/nwhyexport/blog-xml.php");
//赋值部分
function initNews(mc:MovieClip) {
for (var i:Number = 0; i<newsxmllen ; i++) {
mc.attachMovie("mc_each_news","news"+i,1000+i);
mc["news"+i]._x = (i/5<<0)*345;
mc["news"+i]._y = (i%5)*28;
mc["news"+i].url = newsxmlroot.childNodes[i].attributes["b_url"];
mc["news"+i].txt_title.text = newsxmlroot.childNodes[i].attributes["b_title"];
mc["news"+i].txt_time.text = newsxmlroot.childNodes[i].attributes["b_date"]+" | By-"+newsxmlroot.childNodes[i].attributes["b_author"];
//mc["news"+i].txt_time._x = stageW-mc["news"+i].txt_time._width;
//TweenLite.to(mc["news"+i].txt_time, 1, {_alpha:0});
loadHandler(mc,i);
}
}
//mc的鼠标效果
function loadHandler(mc:MovieClip, i:Number) {
mc["news"+i].onRollOver = function() {
TweenLite.to(mc["news"+i].txt_title, 0.5, {tint:0xff6600});
TweenLite.to(mc["news"+i].txt_time, 0.5, {tint:0xff6600});
TweenLite.to(mc["news"+i].mc_arrow, 0.5, {tint:0xff6600});
};
mc["news"+i].onRollOut = mc["news"+i].onReleaseOutside=function () {
//mc["news"+i].mc_cbar._visible = ;
TweenLite.to(mc["news"+i].txt_title, 0.5, {tint:0x666666});
TweenLite.to(mc["news"+i].txt_time, 0.5, {tint:0x666666});
TweenLite.to(mc["news"+i].mc_arrow, 0.5, {tint:0x666666});
};
mc["news"+i].onRelease = function() {
getURL(this.url, "_blank");
};
}
下边是后台输出的xml,我用的是php,其他语言自己搞定,哈哈:
<?php
header("Content-Type: text/xml; charset=UTF-8");
$str="<?xml version='1.0' encoding='utf-8'?>\r\n";
$str.="<items>";
require("../config.php");
//需要读取作者信息,所以需要操作wp_users表
$sql="SELECT * FROM wp_posts LEFT JOIN wp_users ON wp_posts.post_author=wp_users.ID WHERE post_type='post' ORDER BY post_date DESC LIMIT 10";
$result=mysql_query($sql);
while($obj=mysql_fetch_array($result))
{
$str.="<item ";
$str.=" b_title=\"".htmlspecialchars($obj['post_title'])."\"";
$str.=" b_date=\"".substr($obj['post_date'],2,8)."\"";
$str.=" b_author=\"".htmlspecialchars($obj['display_name'])."\"";
$str.=" b_url=\"".htmlspecialchars($obj['guid'])."\"";
$str.="></item>\n";
}
$str.="</items>";
echo $str;
?>
下载地址……这个文件组织起来有点麻烦,就不放了。
不早了,睡觉也