blog.Ring.idv.tw

Articles

事件處理-「onClipEvent」vs.「MovieClip.onXXX」執行優先權

在ActionScript 3.0之前的Event Model,簡單來說就像是個各自為政的Model,若是硬要評比的話~好處是簡單易用、彈性大~而壞處是沒有統一的Event Model,容易造成學習者混淆~尤其是當一些小細節被忽略時,往往深埋著不定時炸彈,所以在事件的處理上,了解並掌握它是不可或缺的~

「onClipEvent」and「MovieClip.onXXX」執行的優先權

我們建立一個MovieClip在Stage上,並將它命名為「a_mc」,並在此MovieClip上加些程式以便驗證。

onClipEvent(load)
{
	trace("a_mc(load):"+this);
}

然而在MainTimeline也寫入下述程式:

a_mc.onLoad = function()
{
	trace("a_mc(onLoad):"+this);
}
trace("frame[1]");

然後在此MovieClip的Frame[1]也加上:

trace("a_mc(frame[1]):"+this);

最後一樣「Ctrl + Enter」來看結果:

frame[1]
a_mc(load):_level0.a_mc
a_mc(onLoad):_level0.a_mc
a_mc(frame[1]):_level0.a_mc

從結果來看就可以證明「onClipEvent」的執行優先權比「MovieClip.onXXX」來的高!

範例下載

2007-05-22 15:54:01 | Add Comment

快速上手 - Lucene

Lucene是一個開放原始碼的資訊檢索函式庫,最初是由 Doug Cutting 利用Java程式實作完成的,它目前是 Apache Software Foundation 底下的計畫之一,由於相當的受到肯定,所以也洐生出其它的程式版本,如:Perl, C#, C++, Python, Ruby and PHP。

建立Index

一個個搜尋檔案的方式,其實是相當耗時且緩慢的,所以我們必須先為我們想要搜尋的文件建立索引,就如同書籍中提供在最後面的索引頁,可以幫助我們更快速的找到我們想要知道的東西。

Step 1:假設我們想要索引的文件放置在「D:\index」

Step 2:切換工作目錄到你的lucene目錄夾,並輸入下列指令

D:\lucene-2.1.0>java -cp .;lucene-core-2.1.0.jar;lucene-demos-2.1.0.jar org.apache.lucene.demo.IndexFiles d:\index

若出現以下類似的訊息即代表已成功索引,並會在此目錄下建立一個「index」的資料夾,底下包含了三個檔案,簡單來說就是已被索引的資訊。

Indexing to directory 'index'...
adding d:\index\Wang.txt
adding d:\index\Apollo.txt
adding d:\index\JavaFX.txt
adding d:\index\Silverlight.txt
Optimizing...
500 total milliseconds

Command搜尋

接著我們要搜尋剛剛被我們索引的那些文件中的內容~請輸入下列指令

D:\lucene-2.1.0>java -cp .;lucene-core-2.1.0.jar;lucene-demos-2.1.0.jar org.apache.lucene.demo.SearchFiles

接著會出現「Query:」的提示字元,你就可以輸入你想要搜尋的資訊囉~

例如:

Searching for: ajax
2 total matching documents
1. d:\index\Silverlight.htm
2. d:\index\Apollo.htm

Web搜尋

位於lucene目錄底下有一個「luceneweb.war」檔,請將它拷貝至你的Application Server的部署目錄下,例如:Tomcat or JBoss 等…

以Tomcat為例,啟動你的Tomcat之後,它會將此檔解壓縮成luceneweb的目錄夾,接著請修改此目錄夾底下的「configuration.jsp」如下所示:

//String indexLocation = "/opt/lucene/index";
String indexLocation = "D:\\lucene-2.1.0\\index";

也就是設定剛剛索引文件的目錄位置即可,最後開啟http://localhost:8080/luceneweb/就開始享受Lucene吧~

2007-05-18 17:56:03 | Add Comment

手動下載「天空部落」影音

手動下載「mp3」

請參考「手動下載「天空部落」音樂」。

手動下載「flv」

下載「flv」比較麻煩一點,需要分為二個步驟~

首先我們以「楊宗緯-人質」為例。

點選此連結進去後,開啟檢視網頁原始碼~接著試著搜尋「flvplayer.swf」,會找到如下圖的資訊:

接著必須重新組合URL,如:http://mymedia.yam.com/api/m/?pID=1221862

重點一:http://mymedia.yam.com/api/m/

重點二:pID 參數

接著再點選進去之後,會發現一長串的字串,這些字串其實是會被載入至Flash~

最後試著搜尋「furl」,答案就呼之欲出了~

2007-05-18 10:50:39 | Comments (2)

手動下載「YouTube」影片

想從YouTube下載影音檔,其實目前有相當多的工具~

Vixy.net、GooTube FLV Retriever、YouTube Video Downloader等…

所以這篇的重點是以「手動下載」為主!

我們暫且以「百萬大富翁」這個YouTube分享影片來作為這次的範例。

直接點上述的影片連結進去之後,開啟檢視網頁原始碼~接著試著搜尋「player2.swf」,會找到如下圖的資訊:

現在的重點就在於URL的重新組合,將上圖紅色框框的部份重新組合成:

http://www.youtube.com/get_video?video_id=iQ3AD4dRn6s&t=OEgsToPDskIijLVsqhVh6eFdy28Xvj6W

重點一:http://www.youtube.com/get_video

重點二:video_id 參數

重點三:t 參數 (類似一個session值,做個簡單的防護)

掌握這三點就能隨意下載YouTube的影音檔囉~你也可以自行寫一個全自動的下載器~

由於YouTube是採用Flash Video(FLV)的影音格式,這也有免費的播放器可供下載:FLV Player

2007-05-18 09:27:56 | Add Comment

在「onClipEvent」事件中的「this」處理

我們來看一下簡單的例子~

假設我們放一個MovieClip在Stage上,並在此MovieClip下點程式,讓它能夠隨著播放時進行旋轉~

以下均發佈成Flash Player 8 & ActionScript 2.0的swf file

程式一

onClipEvent (enterFrame)
{
    this._rotation += 5;
}

程式一ActionCode

onClipEvent (enterFrame)
{
	ActionConstantPool "this" "_rotation"
	ActionPush "this"
	ActionGetVariable
	ActionPush "_rotation" "this"
	ActionGetVariable
	ActionPush "_rotation"
	ActionGetMember
	ActionPush 5
	ActionAdd2
	ActionSetMember
	ActionEndFlag
}

程式一的ActionCode是最多的一個,我們再試著將「this」移掉試試:

程式二

onClipEvent (enterFrame)
{
    _rotation += 5;
}

程式二ActionCode

onClipEvent (enterFrame)
{
	ActionConstantPool ""
	ActionPush "" 10 "" 10
	ActionGetProperty
	ActionPush 5
	ActionAdd2
	ActionSetProperty
	ActionEndFlag
}

從上述的ActionCode可以發現精簡了不少,其實我們可以發現它相當於如下列的程式:

onClipEvent (enterFrame)
{
    setProperty("", _rotation, _rotation + 5);
}

最後我們再試著將「this」取代「double-quote」,如程式三:

程式三

onClipEvent (enterFrame)
{
    setProperty(this, _rotation, _rotation + 5);
}

程式三ActionCode

onClipEvent (enterFrame)
{
	ActionPush "this"
	ActionGetVariable
	ActionPush 10 "" 10
	ActionGetProperty
	ActionPush 5
	ActionAdd2
	ActionSetProperty
	ActionEndFlag
}

從上述三個程式的ActionCode數量來看~ 若是硬要雞蛋裡挑骨頭的話,程式二在執行上應該是有較佳的效率,純屬從結果上來推論~

2007-05-14 18:14:18 | Add Comment

Next Posts~:::~Previous Posts
Copyright (C) Ching-Shen Chen. All rights reserved.

::: 分類 :::

::: 最新文章 :::

::: 最新回應 :::