關(guān)于FLASH留言板的詳細(xì)教程_Flash教程
推薦:AS3中的PNG編碼—用FLASH生成PNG注:耗子英語(yǔ)水平一般,可能有寫地方翻譯(或許稱不上翻譯)的驢唇不對(duì)馬嘴,但是希望大家能從這篇文章中學(xué)到一點(diǎn)東西:)呵呵。有紕漏的地方希望大家指正。關(guān)
基于網(wǎng)頁(yè)的留言板,我們已經(jīng)見得很多,一個(gè)完整的留言板包括三個(gè)部分:
1. 顯示留言的頁(yè)面(顯示朋友們給我的留言)
2. 填寫留言的頁(yè)面 (向后臺(tái)提交信息)
3. 數(shù)據(jù)庫(kù)(用于保存后臺(tái)信息)
關(guān)于如何制作基于網(wǎng)頁(yè)的留言板,不去多作解釋,可以參考相關(guān)資料。
就目前而言,F(xiàn)LASH是不可以直接操作象ACCESS, SQL, Mysql 等數(shù)據(jù)庫(kù)的,他只能依靠ASP ,PHP ,JSP等其他的語(yǔ)言來實(shí)現(xiàn)數(shù)據(jù)的提交和查詢。同時(shí),F(xiàn)LASH還可以和XML對(duì)接,實(shí)現(xiàn)一些數(shù)據(jù)的操作。
FLASH和ASP的交互:
無論是ASP,PHP還是JSP等其他語(yǔ)言,原理大都一樣,本人對(duì)ASP熟悉一點(diǎn),所以以下只講解FLASH與ASP的對(duì)聯(lián);
查看FLASH的幫助文件,可以找到好幾種的交互方法,
本人使用最多的還是:
loadVariablesNum(url:String, level:Number, [method:String]) : Void
loadVariablesNum(參數(shù)1,參數(shù)2,參數(shù)3),參數(shù)1為變量所處位置的絕對(duì)或相對(duì) URL,參數(shù)2為一個(gè)整數(shù),指定 Flash Player 中接收這些變量的級(jí)別
參數(shù)3為發(fā)送變量的 HTTP 方法,常用的有"get"和"POST",推薦使用"POST"方法。
例1:新建一個(gè)flash文件,拖一個(gè)可輸入的文本框組件,取實(shí)例名為name_txt,再拖入一個(gè)按鈕組件到場(chǎng)景中,取實(shí)例名為send_btn,在第一幀上寫
{
if(_root.name_txt.text!="")
{
myname=_root.name_txt.text;
loadVariablesNum("write.asp",0,"POST");
}
}
那么,測(cè)試影片后,在文本框中,輸入一個(gè)不為空的字符后,點(diǎn)擊發(fā)送按鈕后,輸入的內(nèi)容,將被提交到同一個(gè)文件夾中的名為"write.asp"中去!
write.asp通過Request.Form("myname")的方法,就可以得到提交過來的數(shù)據(jù),這里就簡(jiǎn)單的實(shí)現(xiàn)了 FLASH向ASP提交數(shù)據(jù)。
接下來看看FLASH如何從ASP讀數(shù)據(jù):
例2:新建一個(gè)flash文件,拖一個(gè)動(dòng)態(tài)文本框組件到場(chǎng)景中,取實(shí)例名為read_txt,在第一幀上寫
_root.read_txt.text=myname;
理論上測(cè)試后,read_txt文本框會(huì)顯示read.asp提交過來的myname中的值,但是有時(shí)候不能夠保持實(shí)時(shí)性,經(jīng)常得不到數(shù)據(jù),相信也有許多朋友
會(huì)碰到同樣的問題,這里講兩個(gè)小技巧。
技巧一:
首先可以在FLASH初一個(gè)變量為 active_old=0; 在ASP中Response.Write("active_new=1")
那么FLASH里可以寫上:
_root.onEnterFrame=function()
{
loadVariablesNum("read.asp",0,"POST");
_root.active_old=active_new;
_root.read_txt.text=myname;
if(_root.active_old==1)
{
delete _root["onEnterFrame"];
}
}
此段代碼表示,開始FLASH會(huì)不斷地訪問read.asp,read.asp會(huì)把變量active_new傳遞給FLASH中的_root.active_old,當(dāng)_root.active_old改變后,
將停止事件。
技巧二:
使用loadVariablesNum("read.asp?temp=" random(10000),0,"POST");的方式,在每次訪問時(shí)會(huì)得到最新的數(shù)據(jù),不會(huì)再使用緩存中的信息。
關(guān)于ASP中的代碼如何書寫,不再多作解釋,重點(diǎn)講解FLASH如何準(zhǔn)確和及時(shí)得到數(shù)據(jù)庫(kù)里的數(shù)據(jù),達(dá)到我們期望的功能。
[備注]
我們常會(huì)碰到,中文提交到數(shù)據(jù)庫(kù)后,數(shù)據(jù)顯示出來為亂碼,主要是由于編碼的原因,只要在ASP中寫上 codePage=”936”%>
FLASH和XML的交互
應(yīng)該來說,用XML和FLASH來交換數(shù)據(jù),還是不錯(cuò)的選擇,首先,XML可以根據(jù)我們的需要,很清楚地定義其結(jié)構(gòu),F(xiàn)LASH也可以很輕易去解釋信息。
例3:
myxml.ignoreWhite=true; //空白忽略
myxml.load(“music.xml”); //加載同目錄下的music.xml文件
myxml.onLoad=function(success)
{
if(success)
{
ReadXML();
trace(“加載成功”);
}else
{
trace(“加載失敗”);
}
}
以上的代碼就能夠檢測(cè)xml是不是加載到FLASH中去了。
以下是個(gè)簡(jiǎn)單的XML文件
name=”song2” url=”mp3/02.mp3” />
name=”song3” url=”mp3/03.mp3” />
XML加載進(jìn)來后,我們需要做的是去解析和提取數(shù)據(jù),為我們所用。
以上ReadXML()函數(shù)就用來讀數(shù)據(jù)。
{
myArray=myxml.firstChild.childNodes; //把myxml的第一個(gè)子結(jié)點(diǎn)所有的數(shù)據(jù)以數(shù)組的方式給myArray
totalNumber= myArray.length; //
for( i=0; i< totalNumber ; i )
{
arr_1= myArray[i].attributes.name;
arr_2=myArray[i].attributes.url;
}
}
現(xiàn)在,我們可以得到的結(jié)果是,在數(shù)組arr_1中保存了所有歌曲的名字,在數(shù)組arr_2中保存了所有歌曲的路徑,我們就可以使用loadSound()等方法制作一個(gè)自己的播放器了!
XML與ASP
Xml和ASP各有各的優(yōu)勢(shì),xml數(shù)據(jù)結(jié)構(gòu)很清楚,但是沒有ASP靈活,而且還可以查詢和修改數(shù)據(jù)庫(kù),所以想一想,假如用ASP來動(dòng)態(tài)生成xml,那么我們就可以兩全其美了!
這里需要一點(diǎn)ASP知識(shí)!
以下一段實(shí)現(xiàn)ASP生成指定的XML。
if request.QueryString("Page")<>"" then
Page=Cint(request.QueryString("Page"))
else
Page=1
end if
pgsz=5
%>
DataBaseName="Manage/Message/Message.mdb"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(DataBaseName)
set rs=server.CreateObject("Adodb.recordset")
rs.open "Select * from Message order by addtime desc",conn,1,1
if not rs.eof then
rs.pagesize=pgsz
Rs.Absolutepage=Page
%>
" Pagecount="" PageSize="" Recordcount="">
i=0
do while not rs.eof and i
%>
" Sex="" Email="" Time="--" Homepage="" Title="" Content="" Reply=""/>
i=i 1
rs.movenext
loop
%>
end if
rs.close
set rs=nothing
Conn.Close
set Conn=Nothing
%>
[備注]
我們常會(huì)碰到,XML中假如有中文,將會(huì)成亂碼,所以只要在flash中寫上
System.useCodePage=true,就OK了!
以上只是些基礎(chǔ)知識(shí),下面具體講解留言板的制作和要害:
效果地址:http://www.u-lee.com/bbs.htm
是我的第一個(gè)版本的留言板
留言板主要包括以下功能:游戲,留言(提交留言),播放音樂(mp3),治理功能(刪除留言)
使用到的技術(shù):AS,ASP,XML, database
需要解決的技術(shù)問題:
1.留言內(nèi)容的分頁(yè)顯示,
2,使用List組件顯示歌曲列表,列表使用XML動(dòng)態(tài)更新,
3,使用ScrollPan組件存放留言內(nèi)容,當(dāng)有新的留言內(nèi)容產(chǎn)生時(shí),自動(dòng)調(diào)整位置,最新留言置頂,
4,加載聲音文件,如何實(shí)現(xiàn)播放完一首歌曲后,自動(dòng)換到下一首,
5,刪除留言自動(dòng)調(diào)整頁(yè)面。
原理是把所有的數(shù)據(jù)用ASP提取出來,然后由FLASH來判定,使用split方法,把數(shù)據(jù)存到數(shù)組里去,需要時(shí),再去取,這樣有一個(gè)弱點(diǎn),就是使用起來,分頁(yè)時(shí),會(huì)把不需要的數(shù)據(jù)也調(diào)用了進(jìn)來,不是很科學(xué)!
接下來講的是改進(jìn)后的版本。原理是用ASP動(dòng)態(tài)生成XML,當(dāng)分頁(yè)時(shí),點(diǎn)下一頁(yè)時(shí),繼續(xù)訪問ASP,從新生成第二頁(yè)的XML,都由FLASH訪問XML,來加載數(shù)據(jù),由ASP訪問數(shù)據(jù)庫(kù),讀和寫數(shù)據(jù)。
V2.0 版本中FLASH原文件共有3個(gè),leave.swf 只是個(gè)容器,把write.swf和leave.swf 加載到里面去。
write.swf為提交數(shù)據(jù),read.swf 為讀數(shù)據(jù).
leave.swf :
兩個(gè)按鈕 , 一個(gè) 查看留言 btn1 一個(gè)我要留言.btn2
btn2: _parent.mess.loadMovie("write.swf");
其中還有, 上一頁(yè) 和下一頁(yè) 以及一個(gè)下拉條
主要代碼:
if (ggg == 1) {
mess._y = 28;
} else {
y = xiala.btn._y;
yy = y/dist1;
mess._y = b_2*yy 30;
}
};
write.swf
(圖片見word文檔)
主要代碼:
this_mc._visible = false; // this_mc 為一個(gè)填寫錯(cuò)誤提示的影片剪輯
this_sex = "先生"; //默認(rèn)sex為先生
function clean() { // 點(diǎn)取消按鈕時(shí),清空所有數(shù)據(jù)
this_name.text = "";
this_homepage.text = "";
this_email.text = "";
this_title.text = "";
this_content.text = "";
}
function emailcheck(str) { //檢測(cè)email填寫是否正確,判定是否有@ 和 點(diǎn)
at = false;
dot = false;
for (i=0; i
if (str.charAt(i) == ’@’) {
at = true;
}
if (str.charAt(i) == ’.’) {
dot = true;
}
}
return (at && dot);
}
clean_btn.onRelease = function() {
clean();
};
send_btn.onRelease = function() { //提交按狃代碼
if (this_name.text == "") {
this_mc._visible = true;
this_mc.tishi.text = "姓名不能為空!";
} else if (emailcheck(this_email.text) == false) {
this_mc._visible = true;
this_mc.tishi.text = "請(qǐng)正確填寫郵件!";
} else if (this_title.text == "") {
this_mc._visible = true;
this_mc.tishi.text = "主題不能為空!";
} else if (this_content.text == "") {
this_mc._visible = true;
this_mc.tishi.text = "內(nèi)容不能為空!";
} else {
myName = this_name.text;
myHomepage = this_homepage.text;
if (myHomepage == "") {
myHomepage = "http://www.u-lee.com";
}
myEmail = this_email.text;
myTitle = this_title.text;
myContent = this_content.text;
mySex = this_sex;
trace(myName);
trace(myHomepage);
trace(myEmail);
trace(myTitle);
trace(myContent);
trace(mySex);
loadVariablesNum("write.asp", 0, "POST"); // 假如填寫的數(shù)據(jù)全部合格,將提交數(shù)據(jù)到write.asp
_parent.page_num = 1;
_parent.prev_btn._visible = false;
_parent.txt._visible = true;
_parent.xiala._visible = true;
_parent.next_btn._visible = true;
_parent.btn2.gotoAndStop(1);
_parent.btn1.gotoAndStop(2);
_parent.ggg = 0;
_parent.mess.unloadMovie();
_parent.mess.loadMovie("read.swf"); //提交后,自動(dòng)轉(zhuǎn)入顯示留言的頁(yè)面
}
};
listenerObject_1 = new Object(); // 偵聽事件,假如選擇了"先生"則this_sex = "先生";
listenerObject_1.click = function(eventObject) {
this_sex = "先生";
};
listenerObject_2 = new Object();
listenerObject_2.click = function(eventObject) { // 偵聽事件,假如選擇了"先生"則this_sex = "女士";
this_sex = "女士";
};
sex_1.addEventListener("click", listenerObject_1);
sex_2.addEventListener("click", listenerObject_2);
stop();
read.swf
以上是一個(gè)空影片剪接,用于放置留言信息, 想想假如我想每頁(yè)顯示5個(gè),那么 我需要復(fù)制5個(gè)這樣的影片,放到場(chǎng)景中, 再把從xml中的提取出來的數(shù)據(jù)注入到每個(gè)影片中的 1-5個(gè) 動(dòng)態(tài)文本框中去.
如何讀數(shù)據(jù),上面已經(jīng)講過了, 現(xiàn)在 只要把數(shù)據(jù)賦給動(dòng)態(tài)文本框中就可以了. 需要注重的是,我們選用的是自定義的文本框,首先確保他是多行的并且是自動(dòng)換行的,所以我們考慮的是,文本框的高度必須根據(jù)內(nèi)容的多少來顯示。以下代碼就可以實(shí)現(xiàn):
this.message_load_mc["message_mc" i].content_txt._height = scroll_1*18;
//一行文本,假如是12號(hào)字大約是18px,那么*18后,就可以得到content_txt._height 了
回復(fù)同樣也是這樣另外,低色的高度也要根據(jù)上面內(nèi)容來確定。
this.message_load_mc["message_mc" i].back_2._y= this.message_load_mc["message_mc" i].back_1._y this.message_load_mc["message_mc" i].back_1._height 2
//得到back_2._y 坐標(biāo)。
完整的代碼:
stop();System.useCodepage = true;
//現(xiàn)在是第幾頁(yè),由_root里的this_nowpage來傳給它,在場(chǎng)景中定義
this_nowpage = _parent.page_num;
temp = 0;
read_xml = new XML();
read_xml.ignoreWhite = true;
read_xml.load("DataSource.asp?Page=" this_nowpage "&" Math.random(10000));
// 刷新DataSource.asp,保證不使用緩存里的數(shù)據(jù)
read_xml.onLoad = function(success) {
if (success) {
trace("OK");
parseXML();
} else {
trace("加載失敗");
}
};
function parseXML() {
name_arr = new Array();
sex_arr = new Array();
email_arr = new Array();
time_arr = new Array();
homepage_arr = new Array();
title_arr = new Array();
content_arr = new Array();
reply_arr = new Array();
total_arr = new Array();
total_arr = read_xml.firstChild.firstChild.childNodes;
//---------總記錄數(shù)-------
totalRecord = read_xml.firstChild.firstChild.attributes.Recordcount;
//---------總頁(yè)數(shù)---------
totalPage = read_xml.firstChild.firstChild.attributes.Pagecount;
_parent.total_1 = totalPage;
//---------當(dāng)前頁(yè)數(shù)--------
now_Page = read_xml.firstChild.firstChild.attributes.CurPage;
//---------每頁(yè)顯示記錄數(shù)-------
page_size = read_xml.firstChild.firstChild.attributes.PageSize;
trace(totalRecord);
trace(totalPage);
trace(now_Page);
for (i=0; i
name_arr[i] = total_arr[i].attributes.Name;
sex_arr[i] = total_arr[i].attributes.Sex;
email_arr[i] = total_arr[i].attributes.Email;
time_arr[i] = total_arr[i].attributes.Time;
homepage_arr[i] = total_arr[i].attributes.Homepage;
title_arr[i] = total_arr[i].attributes.Title;
content_arr[i] = total_arr[i].attributes.Content;
reply_arr[i] = total_arr[i].attributes.Reply;
}
showmessage();
}
function showmessage() {
_parent.txt._visible = true;
_parent.txt.total_txt.text = "一共有" totalRecord "記錄";
_parent.txt.nowpage_txt.text = this_nowpage "/" totalPage;
for (i=0; i
this.message_load_mc.attachMovie("message_mc", "message_mc" i, i);
this.message_load_mc["message_mc" i].name_txt.text = name_arr[i] "(" sex_arr[i] ")";
this.message_load_mc["message_mc" i].title_txt.text = title_arr[i];
this.message_load_mc["message_mc" i].content_txt.text = content_arr[i];
this.message_load_mc["message_mc" i].reply_txt.text = reply_arr[i];
trace(this.message_load_mc["message_mc" i].reply_txt.text);
this.message_load_mc["message_mc" i].time_txt.text = time_arr[0];
this.message_load_mc["message_mc" i].back_2._y = this.message_load_mc["message_mc" i].back_1._y this.message_load_mc["message_mc" i].back_1._height 2;
scroll_1 = this.message_load_mc["message_mc" i].content_txt.maxscroll;
this.message_load_mc["message_mc" i].content_txt._height = scroll_1*18;
this.message_load_mc["message_mc" i].back_2._height = this.message_load_mc["message_mc" i].content_txt._height 15;
scroll_2 = this.message_load_mc["message_mc" i].reply_txt.maxscroll;
this.message_load_mc["message_mc" i].reply_txt._height = scroll_2*18;
if (this.message_load_mc["message_mc" i].reply_txt.text == "") {
this.message_load_mc["message_mc" i].back_3._height = 30;
} else {
this.message_load_mc["message_mc" i].back_3._height= this.message_load_mc["message_mc" i].reply_txt._height 10;
}
this.message_load_mc["message_mc" i].back_3._y= this.message_load_mc["message_mc" i].back_2._y this.message_load_mc["message_mc" i].back_2._height 2;
this.message_load_mc["message_mc" i].txt_1._y= this.message_load_mc["message_mc" i].back_3._y 5;
this.message_load_mc["message_mc" i].reply_txt._y= this.message_load_mc["message_mc" i].txt_1._y;
this.message_load_mc["message_mc" i]._x = 0;
this.message_load_mc["message_mc" i]._y = temp;
temp = temp this.message_load_mc["message_mc" i]._height 15;
this.message_load_mc["message_mc" i].btn1.onRelease = function() {
homepage_num = Number(this._parent._name.slice(10));
str_1 = homepage_arr[homepage_num];
getURL(str_1, "_blank");
};
this.message_load_mc["message_mc" i].btn2.onRelease = function() {
email_num = Number(this._parent._name.slice(10));
str_2 = email_arr[email_num];
getURL("mailto:" str_2);
trace(str_2);
};
}
trace(" " this._height);
_parent.b_2 = -1*this._height 250;
}
以上的所有的操作,測(cè)試時(shí)需要在ASP環(huán)境下。
以上假如有不確當(dāng)?shù)男g(shù)語(yǔ),請(qǐng)諒解!
感謝您閱讀我的心得!謝謝!
可以把“FLASH留言板原文件” 中的內(nèi)容全拷到ASP環(huán)境下
如 /web/index.html 就可以了
文件夾中提供了后臺(tái)治理系統(tǒng)供大家學(xué)習(xí)和測(cè)試flash.rar
分享:Flash中MP3導(dǎo)入及同步歌詞的方法了解音樂的幾種常見格式:1、mp3(mpeg-1audiolayer3):能夠以高音質(zhì)、低采樣率對(duì)數(shù)字音頻文件進(jìn)行壓縮。換句話說,音頻文件(主要是大型文件,比如WAV文件
Flash教程Rss訂閱網(wǎng)站制作教程搜索
Flash教程推薦
- Flash 網(wǎng)頁(yè)新聞浮動(dòng)板的制作(XML應(yīng)用)
- flash基礎(chǔ)教程-鉛筆繪圖工具
- Flash AS教程:用動(dòng)態(tài)遮罩實(shí)現(xiàn)液化效果
- Flash對(duì)聯(lián)廣告及關(guān)閉按鈕的制作方法
- 卡通繪畫中人物透視的簡(jiǎn)單表現(xiàn)
- Flash實(shí)例動(dòng)畫教程:制作跟隨鼠標(biāo)的盤旋花瓣
- Flash8制作漸變風(fēng)格的導(dǎo)航菜單
- Flash片頭loading與MovieClipLoader
- 用Flash 2004編寫簡(jiǎn)單的運(yùn)算類
- Flash8模糊濾鏡繪制逼真青翠竹林
猜你也喜歡看這些
- Flash制作光盤引導(dǎo)動(dòng)畫全過程(前幾節(jié)為靜音)
- Flash 8完美動(dòng)畫設(shè)計(jì)與制作
- 北風(fēng)網(wǎng)web講師李炎恢老師網(wǎng)頁(yè)三劍客之flash從入門到精通59課時(shí)|已完結(jié)
- 新東方4+1flash全部教程
- Flash.ActionScript3.0從入門到精通
- 臺(tái)灣呂聰賢Flash MX視頻教程
- 閃魂:Flash CS4完美入門與案例精解
- Flash8基礎(chǔ)與實(shí)例教程配套光盤
- Adobe Flash CS4 新增功能教程(中文視頻)更新完畢
- Flash AS3.0教程之類入門到精通
- 相關(guān)鏈接:
- 教程說明:
Flash教程-關(guān)于FLASH留言板的詳細(xì)教程
。